When developing add-ons it is often necessary to give an ability to set a number of parameters that affect the whole add-on work to the user. For example, the user can specify a directory for saving/loading files, set some default variables or switch between add-on modes. Of course, the interface for setting such parameters can be placed in the add-on panel, but it is better to place it in a separate add-on preferences panel, which is located in the “Preferences” window under the add-on installation panel.
The main advantage of the add-on preferences is that they don’t reset when Blender restarts. The user does not need to configure the add-on preferences each time, it’s enough to set the necessary parameters once, personalizing the add-on for convenient work.
Let’s create an add-on and define a parameter, placing it in the add-on preferences panel.
In the latest version 2.8 of Blender developers have made many changes in API, so all the scripts and add-ons written for earlier Blender versions (2.7 and below) have stopped working. To run your add-ons in the new Blender 2.8, you need to port them – correct their code to work properly with the new Blender API.
To enable your add-on in Blender 2.80 you have to make the following changes in code:
Blender has its own built-in text editor for writing scripts and add-ons, but it’s much convenient to develop them in external IDEs that provide the user with more features such as autocomplete, syntax highlighting, integration with version control systems and other tools that make development faster and easier.
One of these IDEs is Visual Studio Code from Microsoft. This is a free universal environment that supports development with various programming languages, including the Blender API language – Python.
Creating separate elements of procedural textures in Blender is quite simply – find the desired formula, rebuilt it using mathematical nodes, and as a result, get the desired shape. However, textures created this way have one feature – no tiling. Tiling – a cyclic texture duplication, most time is considered harmful, and professional 3D artists try to avoid texture tiling. But sometimes tiling is necessary, for example, when creating patterns or ornaments.
The procedural texture element is always created in a single instance. This is because all the mathematics that forms the actual procedural image is based on the initial data – coordinates that start from 0, spread out to infinity and not repeat. However, the same mathematics helps us to solve this problem.
All procedural textures in Blender are based on math. Even such irregular structures as “Voronoi” and “Noise” are actually generated according to the mathematical formulas. An exact mathematical algorithm is sewed up into each base material node to obtain the desired image as a result.
We can not specify such algorithms in Blender in the usual mathematical format. However, among other nodes, Blender provides us the “Math” nodes – the wrap over simple mathematical operations. Using these nodes we can build complex mathematical algorithms yourself, generating interesting textures.
When starting Blender from the console it processes all parameters passed through the command line. However, some scripts and add-ons for proper work may require specifying their unique command line arguments. If you specify such additional parameters in the command line, Blender will also try to process them, which is likely to result in an error. Blender provides a special way to exclude such arguments from own processing.
The single object visualization most often is performed on a clear white background. It is difficult to achieve this through the common configuring the scene – increasing the illumination of the scene “lights up” the object, decreasing – the background becomes gray instead of white. If the object itself can be simply rendered on a transparent background and then imposed on white, but what about its reflections?
Let’s consider the way how we can render the object and its reflection on a white background.
It is convenient to use the following system for debugging developing multi-file Blender add-ons. But it has one drawback: modules imported in __init__.py file becomes available only after the file running (after the execution of the register() function). This means that any access to the imported modules before they are registered will cause an error. This is not critical in most cases, but it will cause a problem if, for example, in one imported module is used inheritance from the class, described in the other imported module, because the classes descriptions are processed before the add-on registration.
To get more freedom working with imported modules, we can use another way to debug the add-on – do not run the add-on directly from the development directory, but install it in Blender and check its “live” work. However, manual add-on reinstallation requires a set of routine actions, which complicates such sort of debugging. This issue can be solved by reinstalling the add-on in automatic mode.
In order to achieve the desired texture mapping on the object surface, we need a convenient tool for manipulating the texture coordinates. Especially for procedural textures mapped to the object without using UV-s.
The “Mapping” node combines tools for texture moving, rotating and scaling is suitable for most of the texturing tasks. But sometimes its power is not enough. Its major drawback is that it allows setting adjustment values only in certain fields within the node body. These fields have no inputs and cannot be connected to the other nodes.
However, we can implement the required functionality devoid of the “Mapping” node lack with the help of some other nodes. Let’s consider how to build a node tree to rotate the texture around the Z-axis of the object by a random value.
One of the distinguishing Blender features is that many things can be performed in various ways, choosing the most convenient and fastest for your taste. For example, a screw can be created not only by drawing the profile of its teeth. Let’s try an alternative way:
In addition to common panels (N/T/Properties) and their sub-panels, to display the user interface elements while developing Blender add-ons you can also use pop-up panels appearing on the screen when a user presses a certain key combination or perform any action. The simplest example of such panels is the panel that appears when the f6 key is pressed immediately after adding an object (shift+a) to the scene.
Blender API provides developers the ability to create such panels for their add-ons. Let’s consider the creating of a pop-up panel as an example of the “Message box” window.
Creating thin long objects like pipes and wires is the often task in the interior, scientific of fantastic scenes. One of the easiest and most convenient ways to create such objects is using curves.
The main curves advantage is the easiest control and editing: any time you can change the shape of the curve, move its points, add new and delete unnecessary ones. You do not have to work with a lot of mesh points, but only with several points of the curve, which is much more convenient. Preprocessing for rendering scene with curves is also performed faster than with meshes.
One of the amazing Blender features is that the graphical user interface GUI is not absolutely necessary for its work. You can install Blender on an operating system without a graphical shell and successfully render your scenes. Such types of a Blender installations are usually required to organize various render farms.
For example, consider Blender installation on the server Linux Debian operating system.
Sometimes it is necessary to create a render of an object with shadows on a transparent background. This occurs when you need to realistically embed a 3D into the photo or when creating an image to use it as a sprite in a computer game.
There is no special shader in Blender, like “Shadow catcher” in 3D Studio Max, which remains transparent display shadows. However, it is possible to achieve the desired result.
Let’s consider how we can get a shadow render on a transparent background using Blender:
Sometimes it is necessary to add a single modifier to each part of some complex object. The easiest way is to cycle part by part through all the object and add the desired modifier to each its part manually. But if the object consists of many parts, it will take a lot of time.
There are some ways to greatly facilitate this work:
For an effective portfolio demonstration, there is a good practice to show together with the color render the clay render to emphasize scene volume, lighting, models topology, as well as, in the case of photo-realistic rendering, showing scene “3D-essence”. The overlaying of these two renders in the same image could be an even more spectacular trick.
Blender add-on allowing to interrupt the rendering process and resume it from the interrupted place. For those who are not able to have the powered-on computer for render for a long time.
For example, the whole image render takes 12 hours. And there is no way to have the computer powered on all the time, but it is possible to power it on for 5 hours with breaks. If you interrupt the standard rendering process to turn off the computer – next time render starts from the beginning, and all progress is lost. PartitionRender add-on allows dividing the image into several blocks – partitions, each of them is rendered separately. Choosing division by X and Y in 2 parts, the image is divided into 4 blocks. Each of them will be rendered about 3 hours that fit in the time to work. Each partition after rendering saves to file. The next time (after rebooting the computer) PartitionRender automatically continues with the partition on which the break occurred. After finishing all partitions renders, partitions automatically compile to the whole image in compositing.
In the development of add-ons, their modules should be abstracted as much as possible. For a very simple reason – functional, created for a current add-on, will likely need in the next add-on, and possibly not even in one. In the add-on release, the problem of accessing to such common functionality modules is easily solved – all the necessary modules are included in a single package and distributed together. However, during the add-ons development, such modules are much easier to store separately, in one instance, without associating them with any particular package, and import if necessary the desired modules to the desired add-on.
In accordance with the packages import rules, Python allows to refer modules in the following ways:
In the development of complex add-ons with large code volume storing all the code in a single file is inappropriate. When a single file contains logically unrelated classes, functions, and datasets, it is difficult to read, debug, find the necessary code pieces, reuse code. Such code layout is considered as very bad programming tone.
Blender Python supports modular system that allows subdividing logical code parts of the add-on into different files, and then connect them to use. Even if you have never thought about modules, creating scripts or add-ons, you have already used them – any code stored in the *.py file is a separate independent module. Just your addon consists of only one module. Complex add-ons may consist of several tens of modules.