Press against surfaces with Geometry Nodes in Blender!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
using geometry nodes we're going to take any shape and put it in any other shape which will then conform to its boundaries so it'll allow us to do some really cool effects like pressing an object up against glass or even like filling up another object so it's all about understanding the boundaries and where the intersection point is and it'll all be done in Geometry nodes it also lets us do some cool effects like if we have a glass or a container and we can basically just have all those objects inside smudging against the edges so to begin I'm going to create a new scene I'm going to delete everything create a new sphere go into geometry nodes click new and I'm going to pin this so we can click off and still see the node graph all right to begin I actually don't need the initial sphere that I made so I'm going to just delete the geometry input and let's just create a new sphere we could do UV sphere or icosphere let's start with an icosphere and we can see how we like it I am then going to create the boundary that our mesh will conform to we could obviously create a cube in Geometry nodes but for more versatility so whatever use case you're using this for it could work we're going to just create a cube and obviously we could change this geometry later however we want but for now I'll just keep it as a basic Cube and I'm going to go into its viewports display and I'm going to do display as a wire just so it's not taking up the screen and I'm going to drag this in here and I'm also going to click this to relative so whenever I drag an object from the hierarchy I always click relative so we can move this around and everything will still work okay so we now have a icosphere and I'm going to just up the sub DS on this maybe something like four and we could even make this a little smaller so we have this sphere and then we have this outer bound so the question is how do we get it to smudge or constrain itself to that boundary so for this we actually want to use a raycast node we're going to basically look at every vertices on this sphere and check if it's outside this this Cube and if it is outside we want it to basically smush or flatten to whatever that mesh or that boundary is so the main trick here is to use the raycast node and our Target geometry is this boundary and for clarity I'm just going to rename that to boundary and I'll leave this as sphere which our geometry node stack is on and basically we want to take every vertices position like I said so I'm going to just do a position and when the object is here let's say just like a little bit outside we basically want to raycast from the opposite direction of the normal to the outer side of the boundary and the reason I am recasting backwards is basically I'll show you with I don't know I'll do another Cube here just so you can see when I turn on face orientation it's blue if I let's say delete this one face you'll see the inside of it is red and the outside is blue so this means the normals are pointing outward and here it's the opposite so raycast only can hit things when the normal is blue okay so we have this Cube set to wireframe and if I were to change that to solid you can see it's blue so that's why we need to shoot backwards from these points to see if it hits anything I'm going to switch this back to wire turn off face orientation okay so to do this we actually don't want to do position we want to do normals sorry about that I forgot and we want to do a vector math and we'll do a multiply where is multiply and we basically just subtract minus one so this switches the direction and we'll plug this into Ray Direction so it's pretty simple now we want to basically set the positions of this object so I'm going to do set position and right now it's going to just do its ordinary position but we want to have a certain amount of it the parts that are hidden to get flat in so one we want to know which parts of it are actually hitting and have that in the selection node here and then we want to set that position so the hip is Position will actually work there but now it's actually applying it to everything the whole sphere so you get this kind of crazy shape so I'm going to actually do a vector math and to evaluate which cell which part is outside I'm going to do a DOT product and I basically do a DOT product from the hit normal and this this normal and if I do something like a compare node and I do less than and I plug this in here so this should work let's say I put in the selection here and then I'll say hit position so now you have this area flattening out when it's outside the cube so there's a few things we can do to clean this up a little bit you'll see that their edges are a little bit jaggedy so you could always up the subdivision and it'll get better depending on what performance you have you can obviously lower it and and do a subdivision a different way but I also like to add a little bit of smoothing here so and I can set this to like somewhere between one and two um depending on how what look you want and how hard that edge is that you want I also want to set a a set shade smooth and one other thing to note is this origin this little dot within our our sphere here if it goes outside the bounds currently we're not taking care of it obviously you could add more nodes but I don't want to make this tutorial too complicated so instead I'm going to just add a limit limit location here and I'm going to limit location of everything and I think our cube is my from -1 to 1. so now I can like freely move this sphere around and we won't have or we won't encounter any issues so that's the basic use case for this or way to do it I'm going to show you one more thing in case you want to instance a bunch of objects and um so in order to instance a bunch of objects I could do something like a instance on points and we're going to instance this but uh let's put it here just so we have more visibility of everything and I need to generate some points so I'm going to do a mesh to volume and we could even take our original Cube boundary because we want an instance inside this Cube and then I'll do a points to volume or sorry volume to points uh where is it mesh to volume distribute points in volume sorry that's what it's called and we could do random and select this as our points so I could obviously up the density there's and change the radius here so one issue here is when I'm using this um this outer bound as the the volume in which it's instancing you'll see we sometimes get these instances that are on the edge of this Cube and and like I showed you before we want the origin of each sphere to actually be inside the boundary so in order to do that I'm going to actually do a scale elements yeah I think this is the right one and we can just scale this down a little bit and you see it's starting to contract inward you could always plug this in if you want to see what's happening so you can kind of see what this scale did and we can obviously see where these points are Distributing see where this volume is try and understand how we want to get it so that we can get the result we want something like that will create the points inside the the cube or the outer boundary Okay so this is all nice like so but um I'm actually going to make it slightly bigger because I want to show that that smush effect that we did so this should be working right but it it's currently not flattening on these edges so the reason for that is because we instance these instead of just using the icosphere we're going to have to realize the geometry or realize the instances and then it'll start to work there's one more thing I want to show you and that's the ability to actually change this mesh so I could actually just go in here and create a curve and you'll see we still have this mesh and these objects are constrained and smushed against a curved surface to me I think this is really cool and lets it be super versatile if you want the project file sign up to my patreon and if you like this please drop a like in the sub or even a comment be greatly appreciated and I'll see you in the next one thank you
Info
Channel: Robbie Tilton
Views: 20,591
Rating: undefined out of 5
Keywords:
Id: Dj-2xCb_GKs
Channel Id: undefined
Length: 10min 8sec (608 seconds)
Published: Fri Feb 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.