25 October, 2020

Blender Python Add-on: INSTA-MIST (version 1.0)

 


The process of adding mist to our renders would normally take quite a few steps. First you need to activate the Mist Pass, then activate the Mist Pass in the Viewport, then switch to the world settings and set the start and depth of the mist pass, then finally we need to arrange the compositor nodes.

This is not a hard process but is very much time consuming. That's why I thought it would be a good idea to create the INSTA-MIST Addon and share it with you.

Check out the Preview Video here.

Once you have downloaded and installed the add-on you can access the Panel by Pressing N and Enable INSTA-MIST.

As soon as we Enable Mist, not only will the Render Layer enable the Mist Pass but all the other work as been done for you also. 

The Camera has the Mist Pass Enabled so we can see the length of the Mist. We can make adjustments to the Start, Depth and Falloff type in the INSTA-MIST panel.

The Compositor has also been arranged, leaving you one less thing to do. We can now focus on the composition and making things look good.

You can download the Add-on here.

I will continue to develop this add-on and if you have any suggestions on what you think we should add, then be sure to drop a comment here or on the Preview Video.

I hope you find this Add-on helpful and as always thanks for reading!. 


20 October, 2020

Blender Python Tutorial: INSTA-MIST Add-on

 


 

In this video, we will be creating a new add-on which will help speed up our workflow when working with Mist. 

As Artists, we often repeat the same process over and over (such as adding mist) and though it's not a complex task, it is rather time consuming. 

I wanted to show how easy it was to create a simple Add-on that speeds up the process quickly. Each of us use Blender for different reasons but it's always a good idea to improve your workflow by creating personalized tools like the Insta-Mist.

Not only will we enable the Mist Pass, Enable the Viewport Display in the camera settings, adding the Mist Options to our newly created panel but we will also arrange the compositor for this whole effect to work. So the next time we want to add Mist to our Renders we can simply press a button and let the add-on do the hard work for us.

We will only need a Panel and an Operator, though to make it look better, I later added a sub panel (if you want to know how to add a sub panel be sure to check out our scripting playlist).

You can add the Panel and Operator from the templates or if you want to follow along you can download the template script here.

Alternatively, you can download the finished Insta-Mist script here.

I hope you find this tool and this tutorial helpful!. Be sure to hit that like button and as always, thanks for reading!



05 October, 2020

Blender Python Tutorial: How to Generate a Random Number

 

 

In this video, we will be looking at how we can create a random number and then displaying that number in a Panel. We will also take a look at adding text and Icons and only displaying them based on that random number. 

There are two types of Numbers we can use, Floats and Integers. These are just fancy names for Decimal or Whole Numbers. 

After we import bpy, we then need to import random. This will then enable us to generate a random number.

In this example we will be using a Panel, an Operator and a Property Group, though you can use it for a number of different scenarios. I use a template script which was created in a previous tutorial and if you want to follow along, you can download a blank template here.

Alternatively you can download the finished script here.

If you want to Generate a Random Float (decimal) Number we need to create a Custom Property:



 

If you want an Integer (whole) Number, be sure to change the Property (as shown below):



 

Now we have created a either a Float or Integer Property,  we want to display that Property on our Main Panel.

In the "draw" section of your Panel we can add the Property like so:





 

You will notice the "mytool" reference. This reference allows us to use any of the Custom Properties within our Property Group. We have covered this in a previous tutorial. Be sure to watch the video here.

At this point, you will have a simple Panel with a Property called "Random Number". The Idea is, that when the button is pressed, a Random Number will be Generated and then Displayed. To do this we need to go to the "execute" section of our Operator. 

For the Float (decimal number):



 

 

 

 

For the Integer (whole number): 





 

To generate a random Float or Integer is very similar.

For the Float: x = random.uniform(0.0, 1)

We first create a reference called "x", though this could be named differently. We then use, "random.uniform" for a Random Float Number. Finally we use an argument "(0.0, 1.0)", this first decimal number is the starting number. Which is then separated by a comma and then we have the end number.

For the Integer: x = random.choice(range(0, 3))

Again we start with a reference (if you already have x as a reference, be sure to use something else). We then use, "random.choice" for a Random Integer Number. The argument for this is different, "(range(0, 3))". The first number is the starting point though the last number will not be shown.

So if you want the Random Integer to be between 0 and 3 we need to change it to (range(0, 4)).

Now when we run the script and press the button a Random Number has just been Generated!. Though you can not see anything you will just have to take my word, or you can print the random number to the system console. 

To do this you simply need to type:

print(x) 

or if you want to get a little fancy, you could add a custom message:

print("The Random Number is: ", x)

So, we now know the Random Number is working!. We can delete that line of code (since the system console is just for debugging or errors). Then we can display the Random Number by updating our Custom IntProperty that we created before.

This is really simple and requires only one line of code. Right under the Reference: 





mytool.random_number = x

This code would be the same no matter if it's an Integer or a Float. We are simply telling the random_number Property to change its Value to x, which is whatever the Random Number is.

We can take this further (as shown in the video), and add text or icons which are displayed depending on the random number.

I hope you find this tutorial helpful and as always thanks for reading.