Thursday, November 11, 2010


Today I released a new version of the Bridge script, which brings some new features to the old script. You can read the information for artists on the bridge-page of my website, or visit the BlenderArtists thread. This blogpost however is going to take a deeper look into the code behind the changes. More specifically I'm going to discuss the Cubic Interpolation.

Cubic Interpolation

One of the new features in the script is an interpolation type called 'cubic'. This makes use of natural cubic splines, the same method I used in the LoopTools script.As you can see in the image on the left this results in fluid curves which can be very useful for organic modelling. The problem with natural cubic curves though is that you need more than two input coordinates.

The first two coordinates that are used are pretty straightforward. They are the location coordinates of the vertices that need to be connected to each other. To calculate the spline between them we also need to have two additional input coordinates, one on each side of the vertices. In order to make this a bit more understandable let's take a look at the following example.

The example input is shown in the top image on the right. V1 and V2 are the input vertices. Between them I've drawn the result we wish to get; the spline. In order to get it we need the two additional input points: A1 and A2.

The first step in obtaining A1 and A2 are calculating the tangent vectors of all the edges in the loops. To do this you take the Face Normal vector (blue) and calculate the cross product with the edge vector (red). This gives the Cross vector (green). There are actually two Cross vectors, one facing from the edge to the face, and one facing from the edge to the opposite loop (displayed in the image). We can simple check which one we got by adding the vector to the edge-center and see if we're getting closer to the face center or further away from it. We negate the vector as necessary and then normalize it.

The last step is to calculate the Average vector for each vertex. Simply take the Cross vectors from the edges connected to it and take the average. Adding this Average vector to the location of V1 gives us A1. Note: the size of the Average vector is scaled to be the same as the distance between V1 and V2 and multiplied by the strength factor as given by the artist.

This method works well for loops that are connected to faces, but that isn't always the case. For loops that aren't connected to faces there are two changes. First of all, there is no face normal. An alternative is calculated by taking the cross product of the edge vector and the vector connecting V1 and V2. The second difference is that we calculate the spline per vector, instead of first calculating all Cross vectors. This is because an edge is connected to 2 vertices, and both might be connected to different vertices in the other loop (which is used for calculating the alternative to the face normal). The rest of the procedure is more or less the same.

Tuesday, November 9, 2010

Site update

Perhaps a bit late, but I finally found the time to update my website. No change in the lay-out, but there are some changes in the structure. It now has a clear division between scripts for Blender 2.4 and scripts for Blender 2.5. I've also written an instruction page on how to use Add-Ons in 2.5.

Besides this structural change I've also created pages for two of the scripts I've written in the past months. The first is Index Visualizer, which I discussed in the previous post.
The second script is Icon Display, which shows all the icons that are available in Blender. The code behind this functionality is interesting in that it calls the source-file in which all icons are defined. It then parses this file and displays the icons using the names in the file. Further point of interest is the dynamic creation of operators. This might look pretty easy, but actually has some restrictions. You can't use setattr() and can't create them from within the register() function. I've written a full explanation of this, including sample code, on the blender wiki.

For normal Blender users the Icon Display script is of course not very interesting, but for script-developers looking for a usable icon (or the name of a specific one) it can be pretty useful.