Showing posts with label add-on. Show all posts
Showing posts with label add-on. Show all posts

10 August, 2020

Blender Python Tutorial: How to Create and Assign a Shader Material




In this video, we will be taking a look at not only creating a Shader Material but also assigning that material to the currently selected object.

We can create something simple or something complex but both ways will be using an Operator. We first create a panel where our button will live. Then we can create a simple operator, that when pressed will create and assign a Shader Material to the Selected Object.

If you want the user to have any options, we can easily upgrade the simple operator and make it become a popup dialog box. We can then giver the user control over any setting or option. In this example we want the user to be able to set the color before adding the Shader.

We have covered popup dialog boxes in other posts and videos so be sure to check them out!. Though in this example we will be taking a look at the FloatVectorProperty.

In code that would be:

The Float Vector Property usually looks like this:
If we tried to use this in it's current state, it would kick up an error because as we know to change a Color Value we actually need four values. We need the Red, Green, Blue and Alpha Values.


We can just define the Size and set it to 4 to add another value:

Which would look like this:


Now we have this, it doesn't look great. In fact it looks terrible, we want the user to have a good and quick experience.

So let's change this FloatVector slightly by defining the Sub type.

And that would turn the Float vector into something much more appealing:

If you want to set the default color (here you can see I set the default to green), you just need to define the default like so:

If you want to download the template script you can download the script here.

I hope you found this video helpful and as always thanks for reading!.

30 July, 2020

Blender Python Tutorial: Class Naming Convention





In this video, we will be looking at the correct Naming Convention for our classes. The Class name should be as follows: ADDONNAME_PT_main_panel


ADDONNAME - Using Uppercase, we type the Name of the Add-on. An underscore can be used if the name is more than one word.

_PT_ - it is then separated by two letters which denotes the Class Type (from which the type is inherited).

main_panel - using lowercase, we can type the name of the Operator/Panel/Header ect.

Other Class Types:
  • HT – Header
  • MT – Menu
  • OT – Operator
  • PT – Panel
  • UL – UI list

Here are some examples of Valid Class Names and their Identifiers.













Notice how the Identifier for the Operator is different?.

We do not need to add the OT but instead we must add a full stop. We also do not need to add the '_operator' at the end but I prefer to name it as such.

17 February, 2020

Blender Python Tutorial: How to create a Custom Node Group (Compositor) - [bpy]


In this Video, we will be creating a Custom Node Group for the Compositor.

Custom Node Groups are really useful for speeding up our workflow. We can take a whole bunch of nodes and contain them in a single group. 

We can then define what options we want the user to be able to change.

Download the Template Script here

In this example we are just going to create a really basic Node Group with a couple of nodes, but you can take this further and create some awesome Custom Node Groups. 


As Many of you already know, the Darkfall VFX Nodes Add-on has a many Custom Node Groups and each of them give different effects or results.


The Eye Color Change Node


For example, this Custom Group Node will change the Eye Color of your Actor in your Movie clips. We have a whole bunch of values we can change and it's all packaged neatly in a Node Group. 

You can add what ever nodes you want inside of a Custom Node Group and create your own awesome Group Nodes.



Inside the Node Group, we can see all the nodes that are needed for the Effect to work. The more complex the effect, the more nodes you may have.

What kind of Custom Node Groups are you going to make?








11 February, 2020

Shader Library Add-on - The Neon Shader (update 1.01)



The Shader Library add-on has a new addition. I would like to introduce the Neon Shader!. 

Download version 1.02 here

This Shader can be used for a cool Neon or other types of flickering lights. This was the result from the last Python Scripting Tutorial, where we looked at adding a keyframe and a Noise Modifier to a Shader.

We can control the Flickering by going to the Graph Editor. 


We can speed up or slow down the flickering effect by changing the "scale" value. If we increase the value, it will slow down the flickering. 


You can see in the preview video here, which shows two examples. 

The first is rendered with a Scale value of 1. The second Example has a Scale value of 6.

We can also play around with the Strength, Phase, Offset and Depth to suit our needs and I suggest playing around with different values to get more varied results. 


This Shader can be used for both Cycles and Eevee.
 
I hope you find this Shader helpful and as always thanks for reading!.


17 January, 2020

Scripting Continued - Blender Python - bpy



In this video, we will be continuing scripting our "Object Adder" Add-on.

We will add some more functions such as the Smooth Shading option, Add a Modifier and more.

We also look at creating two more panels (for simplicity we call them Panel A and Panel B). After creating the new Panels we can add them to the Main Panel as "Sub Panels". 





It's really easy to add a panel to another panel and it only requires one property. By adding the, bl_parent_id = 'PT_MainPanel' 
we are telling 'Panel A' to be a child of the Main Panel.



By adding the, bl_options = {'DEFAULT_CLOSED'} 
we are telling the Panel to be minimized by default. If you have a whole bunch of panels open by default it can be a pain for the user to navigate to the section they intend to use.




 Once we are happy with the Add-on we need to make sure we add the bl-info at the beginning of the script (you can see the full script below). 

Without this Information, we can not install the Add-on. 







With our add-on now installed, we can use it without needing to run the script nor mess around with any settings.


  

Of course this Add-on is super simple and we can always add, change and improve this add-on but I wanted to create something easy to follow and I hope I have managed to inspire you to take this further and start to make awesome add-ons!..

If you want to use this script you can copy and paste the text below or you can click here.

In the Next Tutorial, we will be creating an Add-on that's a little more advanced but with the knowledge we have learned over the last two videos, it should be easier to pick up.

Again, I hope you found this Tutorial helpful! be sure to let us know what you think of this series or if you want more videos like this? 



Script result : 

__________________________________________________________________________
 


bl_info = {
    "name": "Object Adder",
    "author": "Darkfall",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D > Toolbar > Object Adder",
    "description": "Adds objects and other functions to help our workflow (Tutorial Result)",
    "warning": "",
    "wiki_url": "",
    "category": "Add Mesh",
}

import bpy

    #This is the Main Panel (Parent of Panel A and B)
class MainPanel(bpy.types.Panel):
    bl_label = "Object Adder"
    bl_idname = "PT_MainPanel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'Object Adder'
   
    def draw(self, context):
        layout = self.layout
        layout.scale_y = 1.2
       
        row = layout.row()
        row.label(text= "Add an object", icon= 'OBJECT_ORIGIN')
        row = layout.row()
        row.operator("mesh.primitive_cube_add", icon= 'CUBE', text= "Cube")
        row.operator("mesh.primitive_uv_sphere_add", icon= 'SPHERE', text= "Sphere")
        row.operator("mesh.primitive_monkey_add", icon= 'MESH_MONKEY', text= "Suzanne")
        row = layout.row()
        row.operator("curve.primitive_bezier_curve_add", icon= 'CURVE_BEZCURVE', text= "Bezier Curve")
        row.operator("curve.primitive_bezier_circle_add", icon= 'CURVE_BEZCIRCLE', text= "Bezier Circle")
       
       
        row = layout.row()
        row.operator("object.text_add", icon= 'FILE_FONT', text= "Add Font")
        row = layout.row()
       


    #This is Panel A - The Scale Sub Panel (Child of MainPanel)
class PanelA(bpy.types.Panel):
    bl_label = "Scale"
    bl_idname = "PT_PanelA"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'Object Adder'
    bl_parent_id = 'PT_MainPanel'
    bl_options = {'DEFAULT_CLOSED'}
   
    def draw(self, context):
        layout = self.layout
        obj = context.object
       
        row = layout.row()
        row.label(text= "Select an option to scale your", icon= 'FONT_DATA')
        row = layout.row()
        row.label(text= "      object.")
        row = layout.row()
        row.operator("transform.resize")
        row = layout.row()
        layout.scale_y = 1.2
       
        col = layout.column()
        col.prop(obj, "scale")
       


    #This is Panel B - The Specials Sub Panel (Child of MainPanel)
class PanelB(bpy.types.Panel):
    bl_label = "Specials"
    bl_idname = "PT_PanelB"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'Object Adder'
    bl_parent_id = 'PT_MainPanel'
    bl_options = {'DEFAULT_CLOSED'}
   
    def draw(self, context):
        layout = self.layout
       
        row = layout.row()
        row.label(text= "Select a Special Option", icon= 'COLOR_BLUE')
        row = layout.row()
        row.operator("object.shade_smooth", icon= 'MOD_SMOOTH', text= "Set Smooth Shading")
        row.operator("object.subdivision_set", icon= 'MOD_SUBSURF', text= "Add Subsurf")
        row = layout.row()
        row.operator("object.modifier_add", icon= 'MODIFIER')
       
  
       
    #Here we are Registering the Classes       
def register():
    bpy.utils.register_class(MainPanel)
    bpy.utils.register_class(PanelA)
    bpy.utils.register_class(PanelB)

    #Here we are UnRegistering the Classes   
def unregister():
    bpy.utils.unregister_class(MainPanel)
    bpy.utils.unregister_class(PanelA)
    bpy.utils.unregister_class(PanelB)

    #This is required in order for the script to run in the text editor   
if __name__ == "__main__":
    register()