Turn ANY object into a tree with Blender!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'm fading [Music] foreign [Music] [Applause] have you ever needed the tree with a specific shape and looked for them online and you just can't find a tree that will have the exact shape you need now it's possible you can save hours by easily modeling the shapes you need for example filling the corners of a room by just drawing and making anything you can imagine like a character the tool is called any tree which I have spent months working on and it's really good at making trees and bushes of any shape go check it out the leather Market to see if it might be useful for you we will build a light version of it together which will do some of the stuff the full version does and also we will learn a lot of useful things along the way so hang on first we need an object to turn into a tree then we need to make a grid around it then we need to delete the parts that are outside the object then we need to merge the remaining things by distance find the shortest path from one point to all the other ones then smooth and profile them add UVS and leaves and it's ready and you can use literally any object with the system so let's get started and the first chapter is the object so which kind of an object are we going to use not the default Cube but something even better which is the monkey we will just open up a new side panel here open up Geometry nodes press n and start with the next chapter which is making a grid around the object so for that add a new set of geometry notes and let's disconnect those so that we don't see the cube anymore now what we need is to basically understand how we can make a grid that follows the shape of the object in an extremely convenient way our main helper will be the bounding box node so let's add a bounding box note here and let's drag in the Susan to this node tree and let's connect these using the bounding box and the bounding box to the output and to see well this creates a thing around the Susan for example when I move the Susan around nothing happens well we have to select the bonding box and change the Susan to be a relative and now we remove this you see the bounding box changes its size and shape depending on how big or large the Susan is so now we will use this information this Min and Max here to build our own grid system so first let's pin the geometry nodes three here so that it doesn't move when I select anything else and let's add a grid node here and let's output this like that as you see it is currently very small let's make it a bit larger like that this will be our first plate and this will be moved at the most bottom location of this monkey and the last one would be at the most the highest location right so let's add some separate XYZ nodes so that we can get some information out of here so first you have to move this thing at the bottom most location of this monkey and for that we can use the minimum Z position of this spawning box so let's add a transform node after the grid like that and let's drag and let's use this Z position here so for that we need also a combine XYZ because we cannot put this float C into this Vector translation let's put this into the combine X YZ and move this here so now you see this is exactly at the bottom location which is extremely good and when we move the monkey around it always stays in the correct location now we just have to move it around with the monkey as well because this isn't happening right now so to move it around let's look at this from the top and for example when I move this on the X like that for example here then this should be around here if I'm not mistaken and because we are moving the center point of the object then we are moving this location you're moving from here to here this distance between here and this location just so happens to be the average between the Min and the max of the bones of the monkey so we need to get the average right of the X Min and x max so to get make this a little bit easier I'm actually going to just group those nodes here and I'm going to calculate the average by using a math node add those axes together because the formula tells us to do that this is the formula of the arithmetic average and I'm going to do this actually for the Y as well so now I can just output those from here and here press n group and call this x average and Y average close this and let's come up from here let's call this the ranges and let's use the X average as the translation and Y average also so now when we move this monkey around you see it always is sticking to the monkey and this is exactly what we it however when we make the monkey larger this size isn't exactly sufficient it is not changing its size depending on the size of the monkey so to do this what we would actually need is to get the size to be the X range the range on the x-axis and the size why the range on the y-axis so if you want to get the range of something from the negative to the positive which in currently happens to be two then we have to subtract from the maximum part the minimum part because 1 minus minus one is two so let's build into our range system a system for ranges and let's do this so by subtracting from the maximum the minimum setting this to subtract adding here three of those so from the max y from the max Z the minimum Y and the minimum Z and now those things here should be output from here and that's called this x range y range Z range let's get out from here and now we can just use the X range as the size X Y range is the size Y and the Z range will be useful in a second so now this is moving exactly with the monkey doing everything we wanted to do and let's just go on and let's duplicate many of those on top of each other so that they act basically as layers along with the monkey so let's use a duplicate elements node which allows us to duplicate this thing and currently it's duplicating points but we don't want this we want to duplicate faces and let's add for example 10 faces and you cannot see those because they are all in the exact same location and you have to move them apart so that we can see what is actually happening here so let's take the set position node put this here and for example we're going to put the duplicate index into the offset you see they slide away like that because the index gets put into all of those at the same time which means they're gonna slide but we are going to put this only into the Z component so let's add a combined x y and the Z and put this here and put the index into this one so the first one gets Smooth by zero the second one by one the third one by two to make the move a little bit closer what we actually need is to alter this index by some ways and one of those would be to multiply this by a number for example by this small one and now this is pretty much perfect but we would like this to actually be touching the exact end of this monkey to be at the last like level there and also taking into account the number so for example when we add more they are all stretching together and forming this nice grid for us and this is pretty easy because when you know the minimum and the maximum position of this monkey like that let's say this is like the range is 3 between those two 1.5 and minus 1.5 then we just have to divide this range by the amount of things we have which is 29 and we have a small range for each one of those so they can be placed like that let's do this let's get the Z range which we have calculated and let's use a math node and divide I'm going to shift right click drag reroute here and let's divide this by this number so to divide by this you actually need an integer and I'm going to take the integer and put this here and here and add like 11 here and then we just have to connect this division into this multiplication error and you see it kind of works for example when you add more it always works but we are actually having always one plate less so we can just take a math node and put an addition here and add one plate more so now we have this grid working perfectly and it's ready for our experimentation so this chapter is finished if you need to look at the notes they are here and the next chapter we will make discrete disappear outside of this monkey so we only have the inside so let's convert those into points so that you can actually see what is happening here so if I convert those into points well we kind of have a little too little right now so let's just add some more resolution here like that and I'm going to also turn down the size of those points so as you see we have some points inside of the monkey and some points outside how do we delete those that are outside of the monkey so if you have a shape like that for example we also have some points inside of it like two here and two outside to make the difference between those what we need is to First find the closest face each 3D surface that is polygonal is divided into faces and for each point we'll have to find which one is the shortest closest face to those now what we will do is that we will draw a vector from each point to the respective closest face it has we will do this Vector for every point that we have and at last we will find the normal of this face at least the closest one this will be just like pointing to where the face is pointing you have a good normals if they are bad you cannot well do this and now we have basically the answer to the question which points are inside because we can just compare if those arrows are pointing in the same direction for example for this they are so this is inside this point and this point is also inside big stair pointing in the opposite direction this point is outside and this point also so we'll just have to compare those using a DOT product and this will work out so let's do this first we have defined the closest surface element to each point and for that we can use a sample near a surface node that we can put here and we want to find the nearest surface point of the Susan respective to every point that we have and we need to know the position of this nearest surface element so let's take a position and plug this here so this one is the nearest surface element now what we need is to draw a vector from the original point to the scenarious surface element and for that you can imagine that you have for example a grid like that once you get from this point to that this one has the location of two and one this one has the location of zero and zero so the vector by which you have to move is to 1 which we get by subtracting from the end the start if you do this the inverted wave we would get 0 minus two would be minus two minus 2 minus one this will give us the wrong Vector which we don't want let's subtract from the end to start so from the sample position the start and we can use this Vector method at subtract from the end position we subtract the start position and we get the direction to closest now what we need to find is the normal at this same exact surface element and for that we can just basically duplicate this thing here and find from the Susan monkey the normal so let's add a normal node here and plug this here notice we know the normal and the direction the closest we can just use a DOT product node a DOT product will output -1 for the arrows that are pointing in the opposite directions and one for those that are pointing in the same direction so so now if you preview this with Ctrl shift click and using the set position as the geometry to preview this on you can see a problem you can just set the monkey to the relative position and if you hide this monkey now you can see that we have some white things inside which are inside the monkey so now we just have to make a Boolean value out of those to use this in delete geometry so if you use delete geometry here and the plug is there right now we should get a better result you see it inside this kind of lost but we actually need the inverse of this so let's use a compare nodes and set it to less than zero and now we have the inside of this monkey if you see some artifacts outside of this monkey you just have to add more subdivisions to the Susan by pressing Ctrl 1 for example and the problems should be solved right now now chapter 3 is finished and we can go on to chapter 4 which is merging them by distance this chapter only lasts for a few seconds as we take emerge by distance node well merged in together and this is done so we can move on with the chapter 5 which is finding the shortest path and making this look like a tree this is how the nodes look before we move on to the chapter 5 about finding the shortest pass so let's move on to chapter five and start by adding this shortest path gank here so we need the shortest Edge path node and also Edge paths two curves and these two are working together to create a tree now if you want to know more about those notes in a very detailed way there is a patreon tutorial I have where I literally talk about every input and output there's no these nodes have different examples how to find not only the shortest but the easiest path if you're interested this is something you could look at currently we are just using them at a really low level so you only need to know that the end vertex is actually the start of the tree and the next vertex index goes into the next vertex index and that's all we need so as a very easy example this would work something like that so you can select an index and it starts to grow from there but the problem is well it doesn't look too much like a tree and it's very hard to find for example the lowest index by just changing the number like that it seems this one worked though so we will build a system that uses an empty an empty sphere like that and then it will find the closest point to do this empty and use this as the input to This n vertex so let's do this let's drag in the empty here and I'm going to make some more room for ourselves here to know if something is closest to an empty we have to know the distance to every point in this object so for that let's use a vector math node and set it to distance modes and from the location of the empty and between the position of every element we have I want to find the distance and this looks something like that where the empty is closer you see it is getting darker and further away it's getting white which means it's getting higher as a value now we need to find the smallest of those values so for that what we can use is an attribute statistic node I will delete this viewer for a moment move this thing here and then we can move this attribute statistic here and find the minimum value which will look something like that so that of course you have to also connect the attribute here because we want to get the minimum value of this attribute and you see when I move this thing around the minimum gets larger of course and when I get really close it gets really dark because it's really close to points now we need to find if there is a point that is equal to the minimum distance and for that we can use the compare nodes I by the way pressed Ctrl H you hide this like that and you can use equal if the minimum is equal to the distance somewhere then this is the point that is the closest one to our empty and as you see it works very fine works very nicely and you see it just works you know so we can use this as our n vertex like that and turn on the edge plastic curves with M and this is something but it's not definitely a tree it looks pretty random to be honest so when I move this around it does work it changes but it doesn't look very good and that's because it's not using the edge length as something to consider the pattern by so we actually should use as The Edge cost which is kind of telling the algorithm which path to travel we should use the edge length which we can get by using an edge vertices node so this gives us information about the one vertex and another one of an edge and we can calculate the distance between them by using the same distance node like that between the position 1 and position two we can calculate the distance put this to the Edge cost and you will see this looks much better this looks much more like a tree like a tree I'm gonna put this like that you can see the difference right this is before like that and this is after this is there is definitely difference feel free to look at the notes before we move on to chapter six about adding the profile and converting those things into smooth meshes let's go on and to do this well there is nothing easier than just using a curved to mesh node so let's use a curve to mesh and let's use a profile also but caused a good curved image is nothing about a good profile which looks like that very thick let's use three centimeters here 16 as a resolution to save on performance now this looks a bit heavy and this also is a bit wrong because the branch tips are extremely thick and they Branch starts are also very thick so let's set the resolution sorry the radius of the curve curve radius to the length of the curve because we need a value that is large here and small here gradually and the length of the curve since it starts to be calculated from the branch tips to here since this one here is our end vertex the length works very well and we can just use a spline parameter put this here and use the length faster radius and well I would say this is pretty good looks pretty nice but it's very very very jacked let's make this a little bit better so let's use a fillet curve note and put this for example after this thing here and this looks like a mess but we are here to solve the problems set this to poly and check limit radius and then tweak the radius manually a little bit like that and then you can add a little bit of loop Cuts or just cuts here and this looks much better so this is before this is after and you see there are some problems here like that and these are because we are filleting uh after setting to curve radius so the spline parameter is taken like from the wrong curve so let's just hold down alt and move this before and just see the same problem that was there is now solved which is extremely nice if you have a problem solved chapter 6 finished it's time for a chapter 7 which is adding UVS and leaves kind of the last one actually before it is finished and looking like a nice little tree UVS are no dark magic they are actually just the direction for the texture so for example a UV map like that is just telling us that you know you have to move like that on the x-axis and like that on the y-axis when you combine those as a color Vector this looks like that very familiar and this is basically what gives our branches a UV texture first let's well what can we use as something that goes along the branch as a UV well something like that is of course the length of the a branch and we can use the same spline parameter as that let's preview this spline parameter at for example this geometry and we see absolutely nothing but we know a solution for that and the solution is to use a capture attribute so why do we have to do this that's because this spline parameter is there for splines so if I for example would look at this at the splines here you see it's darker up here and brighter down here and when we convert this to a mesh there are no splines left and therefore we don't see this attribute so we just have to capture the length beforehand and output this no and you can see now this comes with the mesh and looks pretty nice on its own even as a texture I like this this is our either U or V doesn't matter UVA I would like to call this and then we need a UVB which is like the second component of the UV vector and this is basically just the length of the curved Circle here so let's just use the capture attribute like that and this moves around I hate this so let's turn off auto offset and let's and take this one here like that and let's put the same spline parameter here and now we can just preview this at the end geometry and you see well it looks pretty much like something that is going around the branch like that so let's output those two things as a vector let's use a combine X Y and Z put this one at an X this one has a y really doesn't matter you can invert the macros if it doesn't work and let's preview this this looks like that like a UV map I would say so of course you cannot use this in shaders in any ways right now so we have to first store this as an attribute as a named attribute to be more precise and this is a vector because it's purple and we can call this a 3 UV which is the exact same name that any tree uses if you decide to get this you should decide to get this then we can output this as an attribute like that and delete this viewer here so now we have this tree UV attribute and we're going to go to shaders then we've got render View and we don't see any difference because we actually haven't applied this material so let's use a set material at the end of our node tree and select the same material now let's for example add a checkered texture here and preview this and you're like well this looks pretty ugly because we are not using the UVS so let's use the UVS and for that we need to add an attribute node attribute and right in here you guess this right 3 UV and connect the vector or colored vector and look at that we have those UVS here they're looking pretty nice although they're a bit stretched a bit stretched on the length here so we can just use a vector math set this to multiply one and multiply an axis with with a value like for example two in this case and this looks pretty fine I'm going to import the materials from this fine tune any tree addon and let's use a Brown Bark for example and the brown bark looks pretty good on this little tree here the next question is how do you add leaves and this is exactly what we're going to do now so you add the least we need some points to add the leaves on and for that well we need some points as I told you and I think the smooth curves would look pretty nice as points so I'm going to take smooth curves and use a curve to points node like that and now we have 10 points per each curve and for small curves this is very dense so we don't need this we have to actually use a length for example like that and I think this is working pretty okay actually and let's now instance some things on those curves so I'm going to use an instance on points so we need a leaf and below this Leaf in the stem and the stem is helping our Leaf not to stick into the bark which looks extremely ugly so let's use a quadratic bezier for that which is a fancy word for a simple curve let's use this as the instance and well we have some things here looks rather ugly I'm going to join this together with the three in the end so we can actually see what we are doing right like that so that we don't need this viewer anymore and actually let's make some room for us like that all right so currently the quadratic bezier is just so wrong so let's just select everything and put this to zero and now let's zoom into our tree and let's start by increasing this thing here right so now you see they are like pointing up from the branches which is a good Improvement and let's use like 0.05 like five centimeters which is two inches for you Americans now let's put a leaf on top of each one of those and we're gonna deal with this middle one in just a moment so here we instant stems now we just need another instance on points node instance on points and Virgo instance the leaves on those things so where do we get those leaves from of course import leaves and we have those here but of course you don't have this add-on right now so I also included those ivy leaves in the description so you can just get those from there or you can get any tree put this geometry into instance and you see absolutely nothing this is a problem of course this is actually a massive problem I don't yeah they are there you see right they're they're in the wrong position so we have to do so that we separate those children and also reset them so they are in the correct position and now when we take the scale down to like 0.1 then you see we have a mess here so let's select pick instance so it picks only one leaf per stem per Point instance on but it also selects you know per every point that the quadratic bezier has and it has 16 right now so let's I mean we can also turn this down to like eight but a better way to control this is to use endpoint selection which is a really good way to just select the endpoints so put this into the selection and now it only selects one from the start and the other one from the end and we need only the end one because the third one is near the branch and there we don't need this also you probably notice it's pretty complicated to see what you are doing since we don't see those branches anymore or the stems so let's turn those stems into a mesh like that let's put a curve to mesh down here curved mesh and let's use a profile curve as we always do let's use a curve Circle put this here and let's join this together for example join geometry those two things Ctrl right click drag disconnect put this here and you see right there are some massive Rings here and we actually need to reduce this thing so I'll put like one centimeter here now this is a bit better so the radius is still a bit massive so let's use a set curve radius and we would actually want this to be thicker at the start thinner at the end so for that again the best note there is this spline parameter that we can take put the length into radius and you see it is inverted so actually let's use the factor and let's use a color ramp to invert this and this color ramp Works in a very nice way so we can just invert the handles like that and this works and what we also can do is to just use a math node to take down on the thickness a little bit like 0.1 for example I don't want this this last end you don't want this to be like infinitely thin like that and also goes the same for branches you know do I want this you don't want this end to be like that so here where we are using this thin ends Prime parameters that could radius like that let's just use a math node to add something to it like 0.01 and now this is a bit thicker and looks much better so let's go up here again and now we have the radius set to our liking so now when you look at this tree you see a huge problem or actually many of those but the first problem is what I see is that those stems are very straight and we want them to be a bit more curved so for that you can just go here curve them a little bit like that make sure the Z is at 0.25 now obviously that the leaves are absolutely ignorant at the rotation of the stem below them so we should actually rotate them or align them to the rotation of the curve and for that we can use a curved tangent that is basically a normal of the curve is like pointing away like that but a curve of tangent is pointing from the curve basically like that so it's like touching the curve you know 90 degrees of an angle from the normal so we can use the tangent and an align Euler to Vector nodes to align the rotation sorry tangent close to the vector to line the rotation to the vector which is the tangent using this Aster rotation X Y and Z nothing seems to work Z actually works we just have to rotate those leaves a little bit more I'm going to rotate those on the y axis actually like 180 degrees and now this works pretty perfectly things are working nicely now a problem that you see probably is that all the leaves are having the exact same size and we can solve this pretty easily by just using a random value this is like the bread and butter of geometry nodes use a random value like that and this looks already I would say pretty nice so now they are also rotated a little bit uh well regularly they are always pointing up they should be actually pointed rotated to the branch so we can actually just drag from the curvity points to rotation to the instant stems and it doesn't work it's inverted so we can just use a rotate spoiler Euler was a guy who has a lot of mathematical accomplishments and a rotation in 3D space is one of those so we can just throw the toiler in the local space and we can rotate this thing like 180 degrees on pretty much any axis and just see it works all right but you know they're all so straight and inside of the branch we don't like that so before we send those into this mesh here and instance a leaf we have this thing I'm going to add a shift right click track reroute like that here I'm gonna move those things a little bit here move those things even more a little bit here and I'm going to add a rotate instances here that can be used to rotate your instances very easily like that for example and I'm going to add a random value here that is a vector random value because we have like three channels here that we want to randomize so I'm gonna track this here and track this one to zero and now I'm just going to try and you should do the same thing just try and see what you like I first want them to be like well not so uh yeah I want him to be like fat like a bit pointed up for so long to think but not too much and I also want them to be on the z-axis they have to be like really randomly rotated around this thing and maybe also add a little bit of like tilt to them so I think this looks pretty nice but we have another problem the problem is what is that that's huge mess here and we don't want this that's because we are adding the leaves uniformly around the whole tree and this is not very good so we should actually use a trim curve node and trim the curve before it gets to curved points so this looks like that we are trimming the ends uh I think you can see this right so we are only adding the leaves to those areas that are you know left and I'm going to delete this and you see this looks immediately better so I think around those parameters this tree looks pretty okay but the problem is that the stems don't have a material well you can fix this very easily if you just add a material to them so you can go into the end and use a set material with the meshed stems like that and we can select the same Brown Bark that was used and look at that the tree is actually ready does this work with any object this is the question of our day and of course we're going to try this out with a Taurus so let's take a Doris let's make it a little bit smaller and now let's just go here and switch every object to a Taurus Taurus and we also have to do this here Taurus and look at that the system just works you know so you can move this thing round you can select where is this thing gonna work you can select this Taurus go to the wireframe mode you can move those things and it's gonna just you know well work so this is pretty nice right now this was the tutorial I hope you enjoyed this and don't forget to check out any tree I would really like to know what you think about that have a nice time see you next time time
Info
Channel: Bad Normals
Views: 73,671
Rating: undefined out of 5
Keywords: blender, geometry nodes
Id: nlAA3ZTgM6s
Channel Id: undefined
Length: 34min 40sec (2080 seconds)
Published: Sat Jan 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.