To get the number of vertices, edges, and polygons in a mesh, we can simply take their amount from the desired data block: “vertices”, “edges”, and “polygons”. However, there is no special data block for triangles in the mesh structure.
To get the number of triangles in the mesh, we need to execute the following code:
Cameras in Blender are always defined by two FOV angles – vertical and horizontal.
One of these angles is always set by the user through the camera parameter – Feild of View (or a combination of the Focal Length and Sensor Width parameters).
To manipulate object transformations with matrices, Blender includes the “mathutils” module in which the “Matrix” class is defined. With this class, you can simply create the necessary transformation matrices – translation, rotation, and scale.
The following command is used to create a scale matrix:
The classic way of localizing a Blender add-on (translating it into different languages) is convenient because requires just a single Blender Python API call – to get the currently used locale. This way is maximum universal, but Blender would not be Blender if it did not provide users an ability to localize add-ons through its own API.
The principle of creating multilingual add-ons using the Blender Python API is not much different from the classical one – we need to create a dictionary with all the variants of translations for all text strings from our add-on and use this dictionary in the localization.
When referring to the mesh geometry – its vertices, edges, and polygons, Blender operates with the original data without the usage of modifiers added to the object.
For example, the number of vertices of the active object, we can get with the following command:
Python
1
len(bpy.context.active_object.data.vertices)
And it will be returned without considering the object’s Subdivision modifier, which modifies the mesh’s geometry, increasing it.
In order to navigate to an URL-address from Blender – to open the required address in the browser, we can use the system operator “wm.url_open”.
To demonstrate this let’s create a simple tab in the N-panel with a single button, by clicking on which the required page will be opened in the browser.
To have the access to the current context, for example, to work with operators, and to the scene data, for example, to work with meshes, we use two predefined structures from the Blender Python API: “bpy.context” and “bpy.data”.
For example, we can pass them to a function:
Python
1
2
3
4
5
6
7
8
9
10
11
importbpy
defmy_func(context,scene_data):
print(context,scene_data)
my_func(
context=bpy.context,
scene_data=bpy.data
)
# <bpy_struct, Context at 0x00000000050EF568> <bpy_struct, BlendData at 0x0000000007FA6408>
However, in the “bpy.context” structure there is a “blend_data” pointer that links to the scene data. With this pointer, we can access scene data without passing it separately and explicitly.
Python
1
2
3
4
5
6
7
8
9
10
importbpy
defmy_func(context):
print(context,context.blend_data)
my_func(
context=bpy.context,
)
# <bpy_struct, Context at 0x00000000050EF568> <bpy_struct, BlendData at 0x0000000007FA6408>