WEBVTT

00:00.000 --> 00:03.384
Blender 4.2 is released, and there are a few things that are

00:03.385 --> 00:07.240
new for the creation of interactive tools using Geometry Nodes.

00:08.340 --> 00:12.234
You now have the power to exactly control where the

00:12.235 --> 00:16.000
tool takes effect in the 3D viewport by clicking on it.

00:16.620 --> 00:21.100
If you go to the Release Nodes page on blender.org and scroll down to the

00:21.101 --> 00:24.920
Geometry Nodes section, you can see a little demo file where I'm presenting how

00:24.921 --> 00:34.180
you can create this kind of In this video, I'm going to show you how to use the new

00:34.181 --> 00:37.360
Nodes in Blender 4.2 to create this modifier.

00:38.600 --> 00:42.200
I also recommend you to check out the other video that I made about the new

00:42.201 --> 00:45.560
Matrix socket, because that's something that we're going to be using in this video.

00:46.200 --> 00:50.100
I also made a video on the Blender YouTube channel about Node Tools that you should

00:50.101 --> 00:52.362
check out before this to get started on the

00:52.363 --> 00:54.600
basics of how to create Node Tools in Blender.

00:55.220 --> 00:56.200
So let's get started.

00:56.201 --> 00:59.732
There are a few new features for Node Tools in Blender

00:59.733 --> 01:03.300
4.2 to make it possible to interact with the 3D viewport.

01:03.900 --> 01:09.420
One aspect of this is a feature to wait for a mouse click when the tool is called.

01:09.720 --> 01:14.700
This can be combined with the information of the mouse position and the viewport

01:14.701 --> 01:18.840
transform to click exactly where you want the operation to happen.

01:19.420 --> 01:22.820
And in this video, I will show you exactly how to set this up.

01:22.821 --> 01:26.386
We will start this setup already with two Node Groups in place

01:26.387 --> 01:29.720
that you can get from the download from the example file.

01:30.200 --> 01:34.080
One is the Impact Fracture Node, which will do the actual geometry

01:34.081 --> 01:39.180
operation that we want to do by cutting into the mesh repeatedly around a center

01:39.181 --> 01:43.920
point and then the other one we will use on top of that to create some variation

01:43.921 --> 01:47.960
and explode the individual pieces that we've cut to make it more visible.

01:48.600 --> 01:52.500
We are not going to create these from scratch, but just use them from the demo

01:52.501 --> 01:54.781
file to save some time and focus on the things that

01:54.782 --> 01:58.280
really matter for the new features in Blender 4.2.

01:58.720 --> 02:00.320
So let's take a look at these new nodes.

02:00.600 --> 02:05.820
Let's add the Mouse Position node and you can see that there is the mouse X and Y

02:05.821 --> 02:10.460
position which is in pixels and the region, width and height.

02:10.860 --> 02:13.671
Both of those are regarding the region of the

02:13.672 --> 02:16.360
viewport that you are executing the tool from.

02:16.361 --> 02:22.140
If I just connect one of these to the group output and then execute the tool in

02:22.141 --> 02:26.500
edit mode, you can see the individual values as I hover over the outputs.

02:28.520 --> 02:31.614
You can use this for example to calculate the

02:31.615 --> 02:34.200
relative position of the mouse in the region.

02:34.600 --> 02:36.560
That is something that we are going to need later.

02:37.020 --> 02:41.926
So let's turn the mouse position into a vector with a Combine

02:41.927 --> 02:45.080
X, Y, Z node and do the same thing with the region size.

02:47.420 --> 02:52.240
Then we need to divide one by the other and map it to a different range.

02:53.560 --> 02:57.389
So dividing by the region size will make sure that

02:57.390 --> 03:01.840
instead of pixels, now these values go from 0 to 1.

03:02.460 --> 03:06.240
We can check that by also connecting this to the output to make sure that this is

03:06.241 --> 03:09.099
being evaluated and then when we run the tool,

03:09.100 --> 03:12.561
you can see the relative position of the mouse.

03:12.700 --> 03:15.415
Now to get a little bit more control, let's go to the

03:15.416 --> 03:18.280
options menu here and turn on the wait for click feature.

03:19.180 --> 03:23.800
This will make sure that the evaluation of the node tree only actually happens

03:23.801 --> 03:26.860
whenever we click after executing the tool.

03:27.600 --> 03:32.640
So if I click on the name of the tool here, we get a different icon for the

03:32.641 --> 03:37.540
cursor and the actual tool is only being executed whenever I click again.

03:38.000 --> 03:42.920
So now you can see the values from wherever we clicked after executing the tool.

03:42.921 --> 03:45.792
To make this relative mouse position a little bit

03:45.793 --> 03:48.660
more useful, I want to map it to a different range.

03:49.220 --> 03:53.419
So let's use the map range node and then instead of going

03:53.420 --> 03:57.400
from 0 to 1, I want to map it to going from negative 1 to 1.

03:57.640 --> 04:00.699
But let's make sure to zero out all those Z

04:00.700 --> 04:04.901
components since we're dealing with a 2D vector.

04:05.040 --> 04:07.207
And now let's execute the tool again clicking

04:07.208 --> 04:09.961
somewhere in the middle of the viewport.

04:10.340 --> 04:14.720
And then this gives us a value around 0, which is exactly what we want.

04:15.600 --> 04:18.240
So this is the relative mouse position that we'll need.

04:18.680 --> 04:22.500
Next let's find out some information about the 3D viewport that we're looking at.

04:22.780 --> 04:24.920
So let's add the viewport transform node.

04:26.300 --> 04:29.480
And this one presents us with two matrices and a boolean input.

04:29.800 --> 04:33.780
The matrices help you with the space transformation for the viewport.

04:33.920 --> 04:36.616
One is for the camera projection and the other

04:36.617 --> 04:39.821
one for the transformation of the viewport.

04:39.920 --> 04:43.600
And this boolean just tells you whether the projection of the camera is orthographic.

04:43.960 --> 04:49.140
For now let's just simply use the view transformation matrix to find out from

04:49.141 --> 04:51.580
what point we are actually looking as the viewer.

04:52.060 --> 04:55.142
Here I'm not going to go into detail about math or

04:55.143 --> 04:57.821
how different projections and transformations work.

04:57.920 --> 05:00.960
I'm just going to show you how you can get this specific effect to work.

05:01.200 --> 05:03.541
There are plenty of learning resources online to figure

05:03.542 --> 05:06.120
out more about this kind of concept if you want to.

05:06.121 --> 05:10.500
The view transform matrix gives us the transformation into camera space.

05:10.780 --> 05:17.161
So to get the location of the camera in our object space we need to invert the matrix.

05:17.480 --> 05:21.380
And from that we can separate the individual transform components.

05:23.160 --> 05:27.880
Now this translation here gives us the exact position of the viewpoint.

05:28.340 --> 05:34.440
So wherever we are looking from at this cube will be the translation here.

05:34.441 --> 05:38.360
Let me prove this to you by adding a mesh line node.

05:38.600 --> 05:42.440
Setting this to endpoints and connecting the translation to both.

05:43.080 --> 05:46.400
And let's just replace the output of the tool with this geometry.

05:46.780 --> 05:49.576
So now wherever this location that we just calculated

05:49.577 --> 05:52.241
is, the tool is going to create a bunch of points.

05:54.340 --> 05:55.700
So let's just run the tool.

05:56.080 --> 05:57.080
Click.

05:57.880 --> 06:00.410
And now if I zoom out you can see that the

06:00.411 --> 06:04.221
points are exactly where I was looking from.

06:04.500 --> 06:05.780
Try that again.

06:08.300 --> 06:09.300
And there you go.

06:09.800 --> 06:13.880
Let's bring back our cube and then add some more nodes.

06:15.280 --> 06:17.460
This here is going to be our viewpoint.

06:18.660 --> 06:24.120
The goal with this setup is to create a raycast from the viewpoint, so from where

06:24.121 --> 06:27.300
we are looking, to the direction of the cursor.

06:27.920 --> 06:31.817
So as we are looking at the cube we want to cast a ray

06:31.818 --> 06:35.640
from the source of our view to where we are pointing.

06:36.400 --> 06:40.388
The viewpoint as the source we already have, as

06:40.389 --> 06:44.000
well as the relative mouse position in the window.

06:44.300 --> 06:48.340
All that is left to do is figure out the direction that we are pointing in.

06:49.460 --> 06:52.307
For that we can use the relative mouse position

06:52.308 --> 06:55.320
in combination with a little bit of matrix math.

06:56.360 --> 06:59.800
Again here I will just apply the math without giving too much background.

07:00.020 --> 07:03.565
But essentially we need to do both the transformation

07:03.566 --> 07:07.880
and the projection of the coordinates into view space.

07:08.340 --> 07:14.880
So we combine these two matrices using a multiply matrices node and then inverting

07:14.881 --> 07:17.420
the result to get the opposite transformation.

07:18.060 --> 07:24.180
And this we can use to project the relative mouse position from view space

07:24.181 --> 07:28.360
into the object space using the project point node.

07:29.140 --> 07:31.847
And plugging in the previous transformation, this

07:31.848 --> 07:35.420
gives us the point that we are clicking on in 3D.

07:35.840 --> 07:40.349
So let me use the previous mesh line setup to prove what

07:40.350 --> 07:43.160
that looks like by connecting this to the end location.

07:43.960 --> 07:49.155
If I run the tool you can see how we get a short line

07:49.156 --> 07:52.540
that is exactly going in the direction of our click.

07:54.700 --> 07:56.622
And things are going to be a little bit more

07:56.623 --> 07:59.161
clear once we actually do the raycasting.

07:59.380 --> 08:00.560
So let's do that next.

08:02.000 --> 08:03.540
Let's add a raycast node.

08:04.680 --> 08:08.480
And as the target geometry we are going to use our group input.

08:09.460 --> 08:13.800
And then for the source position of the raycast we can simply use the view point.

08:15.420 --> 08:17.939
And for the direction we need to calculate the

08:17.940 --> 08:20.500
difference between the two points that we just got.

08:20.501 --> 08:23.295
So use a subtract node and then subtract the

08:23.296 --> 08:26.641
view point from the point that we click on.

08:26.920 --> 08:28.320
And that will be the ray direction.

08:29.960 --> 08:34.340
To visualize the result of this raycast let's still use our mesh line.

08:34.700 --> 08:40.861
We simply need to swap out the end location with the hit location of that raycast.

08:40.960 --> 08:46.300
Let's join the result of the mesh line with our cube and try this out.

08:47.440 --> 08:48.380
And there you go.

08:48.381 --> 08:55.320
A nice simple setup to get exactly the line of our raycast from the point where

08:55.321 --> 08:59.300
you are viewing from to the point that we are clicking on in the 3D viewport.

08:59.620 --> 09:01.260
Raycast it onto our geometry.

09:01.840 --> 09:04.281
So this is the basic setup for the raycasting

09:04.282 --> 09:06.921
that you can use in all sorts of contexts now.

09:07.080 --> 09:11.580
To use the information of both the orientation of the viewport and your

09:11.581 --> 09:14.600
position of the mouse to make tools more interactive.

09:15.240 --> 09:17.654
So now we have all the information that we need

09:17.655 --> 09:20.180
and let's connect the operation of the fracturing.

09:20.181 --> 09:23.260
Let's get rid of this mesh line setup because we don't need this anymore.

09:23.440 --> 09:26.380
And instead put in the impact fracture node.

09:27.380 --> 09:31.120
For the center point we can simply plug in our hit position.

09:32.040 --> 09:35.780
And for the direction we can take the direction of the raycast.

09:37.060 --> 09:41.980
Let's bump up the iterations to something like 20 and take a look if that works.

09:42.680 --> 09:44.900
Yeah, that's already working great.

09:45.160 --> 09:48.535
But one thing right now is that it's not working super well

09:48.536 --> 09:51.440
whenever we have multiple mesh islands already fractured.

09:51.860 --> 09:55.842
What I want to do is to only apply the fracture operation

09:55.843 --> 09:59.020
on the mesh island or cell that I am clicking on.

09:59.420 --> 10:01.700
So let's include that mechanism in the setup.

10:02.180 --> 10:05.240
For that we can use the existing raycast operation.

10:06.300 --> 10:10.880
Let's change the data type to integer and add a mesh island node.

10:12.080 --> 10:14.807
Here we can sample the island index of the

10:14.808 --> 10:17.560
geometry that we are hitting with the raycast.

10:17.760 --> 10:21.420
So that way we know which mesh island we are actually clicking on.

10:22.740 --> 10:26.400
This information we can use to separate the geometry.

10:27.280 --> 10:33.680
We can just compare the island index with the result of the raycast.

10:35.580 --> 10:40.020
That way we separate the geometry of the mesh island that we click on from the rest.

10:40.021 --> 10:44.793
So let's only create the fracture on the selection and

10:44.794 --> 10:48.620
then afterwards join it back with the remaining geometry.

10:49.780 --> 10:51.280
Let's take a look at how that works.

10:52.060 --> 10:53.060
And there you go.

10:54.380 --> 10:57.040
Now there are just a few more things left to do.

10:57.460 --> 11:03.321
Let's reset our cube and then I want to control the selection of this tool as well.

11:03.820 --> 11:07.711
Let's set the selection after we join the geometry

11:07.712 --> 11:10.440
back to just the selection of the fracture.

11:11.060 --> 11:14.820
That way we only select the freshly fractured parts of the mesh.

11:17.000 --> 11:21.640
And on top of this as a last piece I just want to add the randomize operation.

11:23.920 --> 11:27.780
That will create a more interesting result by breaking up the shape.

11:28.360 --> 11:32.200
Let's make this tool a little bit more useful by exposing some of the parameters.

11:32.740 --> 11:38.460
Simply use the existing inputs from these node groups and drag and drop some inputs.

11:40.360 --> 11:44.280
The seed we can reuse also for the random islands operation.

11:45.300 --> 11:47.240
And then let's also expose these two.

11:48.800 --> 11:51.640
So now we have some additional control in the tool settings.

11:52.780 --> 11:56.060
The last thing that I want to do is add some additional randomization.

11:56.500 --> 11:59.573
Right now whenever we execute the tool it has the exact

11:59.574 --> 12:02.840
same seed so we get the same pattern for the fracturing.

12:03.080 --> 12:04.940
Unless we change the seed manually.

12:05.220 --> 12:08.520
But there is a small trick that I want to apply using one of the new nodes.

12:09.500 --> 12:14.260
Since we are probably not going to click in the exact same spot again we can just

12:14.261 --> 12:17.920
use the mouse position to give us a random input.

12:18.640 --> 12:22.000
So on top of the seed we can add a random value.

12:23.760 --> 12:24.760
A random integer.

12:25.560 --> 12:29.500
Let's say between negative ten thousand to positive ten thousand.

12:29.820 --> 12:35.520
That we create from the mouse X and mouse Y as the ID and the seed.

12:36.320 --> 12:39.280
And this is what we use for the seed instead.

12:40.040 --> 12:45.580
So we both have a manual seed that we can pick in combination with a random seed.

12:46.020 --> 12:47.420
Depending on our mouse position.

12:51.000 --> 12:55.180
We can also swap that out with the seed we use for the randomization of the islands.

12:56.920 --> 12:58.240
Let's get ourselves a new cube.

12:59.960 --> 13:00.960
And there you go.

13:01.420 --> 13:03.100
That's the fracturing tool done.

13:04.720 --> 13:05.400
And that's it.

13:05.560 --> 13:08.279
So that should get you up to speed to create more

13:08.280 --> 13:11.660
interactive custom tools for Blender 4.2 and onwards.

13:12.300 --> 13:13.300
Bye!
