GameDev

Blender Tutorials: Object Structure and Optimization, Basic Python Programming, and How to Work in Blender

Blender Tutorials: Object Structure and Optimization, Basic Python Programming, and How to Work in Blender

Learn: Profession 3D Artist

Learn more

Computer graphics specialist with experience in project optimization and automation. The author of an educational series of Blender tutorials aimed at developing 3D modeling and animation skills. I provide high-quality materials for training and improving professional skills in the field of computer graphics.

Subscribe to our Telegram channel "Checkpoint" - a space dedicated to games and their development. Here you will find interesting materials, news, and discussions about the world of video games and the process of their creation. Join us to stay up to date with the latest trends in the gaming industry.

A year ago, Andrey released a detailed Blender course on his YouTube channel. He has been using this powerful tool for over 7 years. The course starts with the basics, making it ideal for beginners, but subsequent lessons also contain useful information for more experienced users, including hidden features of the program. The material was recorded on version 2.90.1, but the knowledge presented is relevant to both earlier versions (starting with 2.80) and the latest version 3.0.0. This course will be useful for anyone who wants to gain a deeper understanding of Blender and master its functionality.

In the third and fourth video lessons, we cover in detail the structure, optimization, and randomization of objects using Blender tools and Python scripts. In the previous lessons, we've already covered the program's interface, modeling basics, and simple operations. Now, we'll delve into more complex aspects of working with 3D objects, allowing you to significantly improve the quality of your projects and increase the efficiency of your workflow. These lessons will help you master important techniques that are key to creating professional 3D models.

Specialist in computer graphics, process optimization and project automation. Author of educational materials and courses on Blender, which helps develop skills in 3D modeling and visualization.

Object Structure

When creating a new project in the 3D editor, a cube appears by default. This object has its own unique data, which can be viewed by clicking on the arrow next to the name of the Cube object in the Project Structure (Outliner). The Cube object data includes the Cube mesh, which is indicated by the green triangle icon. It is important to understand that an object and its mesh are different elements, which allows for more flexibility in working with them during modeling.

Displaying an object and a mesh in the scene collection. For clarity, the object is underlined in orange, the mesh in green. Collage: Leon Balbury for Skillbox Media

An object has a name and characteristics such as position, rotation, scale, and dimensions. These parameters are displayed in the Transform panel, which is located in the Item tab at the top. The panel can be quickly opened using the N hotkey. Using these tools allows you to effectively manage objects in your project.

In Edit Mode, you can view the mesh data. To do this, go to the Transform tab - Element tab. New data will appear in this section, including the Median. The median is the coordinates of the average value of the points, which allows for better analysis of the distribution of data in the mesh.

Mesh coordinates in the Median tab. Screenshot: Leon Balbury for Skillbox Media

Let's modify and move the mesh in the viewport, paying attention to its coordinates. After that, return to Object Mode and notice that the object's coordinates remain unchanged. In the viewport, you can see its origin—an orange dot that represents the object's position and center. This demonstrates that the mesh and the object are two different entities in Blender. Understanding the differences between them is important for effectively working with 3D models and managing their properties.

Object and mesh moved to the side. Screenshot: Leon Balbury for Skillbox Media

Object and Mesh Relationships

Now let's look at why this information matters to the user. For convenience, let's change the name of the Cube object to Cube object (double-click on the name in the project structure), and its mesh to Cube mesh. These elements are in a relationship similar to the Parent-Child relationship, where the Cube mesh acts as a child of the Cube object. It is important to note that an object can only have one child at a time, while a mesh can be a child of multiple objects.

Creating a new cube is done using the keyboard shortcut Shift + A. As with the original cube, the new object will have a separate mesh. However, by going to the «Object Data Settings» tab, (Object Data Properties), we can replace the new mesh with the one we previously renamed to Cube mesh. This allows for efficient resource management and simplifies the modeling process in 3D programs, while maintaining the integrity of the project.

Replacing the mesh of the new object. Screenshot: Leon Balbury for Skillbox Media

The two objects will share the same mesh, which has its advantages, which we'll discuss later.

A note is an important element in any document or material, as it allows you to clarify or supplement previously presented information. Notes can contain references to sources, clarifications of terms, or additional information that will help the reader better understand the context. Proper use of notes improves the quality of content and improves its comprehension. It is important to remember to keep notes brief and to the point so as not to distract the reader from the main topic.

The screenshot shows two objects that have different appearances after performing the operation. This difference is due to differences in their positions and settings. If you return all the parameters in the Transform - Element tab to their original values, both objects will be identical cubes.

Let's conduct a new experiment. Let's delete the previous objects and add a new cube, naming it "cube mesh main." This cube will become the main mesh for subsequent operations. Let's move on to the Viewport Overlays tab. In the first lesson, we activated the Z-axis. Now, let's check the Statistics box to display information about the current scene in the upper left corner of the screen. This will help you better navigate the parameters and characteristics of your work.

Location of the "Statistics" option and a list of data. English: Screenshot: Leon Balbury for Skillbox Media

Statistics indicate the current state of the scene, demonstrating relevant data and trends. By analyzing the numbers, you can identify key aspects that influence the development of events in a given area. This data helps to better understand the dynamics of change and predict next steps. Note the importance of statistics in assessing the situation in the scene, as they provide important insights for participants and observers.

  • 3 Objects - 1/3 means that one of them is selected;
  • 8 Vertices;
  • 12 Edges;
  • 6 Faces;
  • 12 Triangles.

When creating a new cube or duplicating it with the Shift + D combination, the number of all geometry indicators is doubled, since the object mesh is also duplicated. However, if you replace the mesh of a new object with the mesh of a previous one (for example, with a cube mesh main), the geometry values ​​will remain unchanged. This is important to consider when working with models to optimize performance and avoid data redundancy.

The Alt + D keyboard shortcut significantly simplifies creating a new object with the original mesh. Using this shortcut, you can quickly generate multiple identical objects, which allows you to maintain the initial polygon count. This is especially useful for streamlining your 3D modeling workflow and saving time when creating copies of objects.

This operation significantly reduces the time and resource costs of scene calculation. Each polygon has many internal characteristics, such as normal, shading, and other parameters that may seem insignificant at first glance, but play a crucial role in the rendering process. The graphics engine needs to process all this data for each polygon in the scene. Using the same characteristics reduces calculation time, even if this data belongs to different objects, which significantly optimizes rendering performance.

Optimizing Large-Scale Scenes

To complicate the task, select all objects in the scene and use the keyboard shortcut Alt + D to copy them multiple times. It is recommended to delete or hide (H) the camera and light source beforehand to avoid accidentally creating duplicates. Proper organization of objects in the scene will help simplify the work and increase the efficiency of working with the 3D editor.

A group of objects copied several times. Screenshot: Leon Balbury for Skillbox Media

The statistics in the screenshot show there are 310 objects in the scene. To select all objects, use the A key or the Circle Select tool (press C). Increase the selection radius using the mouse wheel. Applying the Subdivision Surface modifier, which we covered in the second lesson, will increase the face count on one of the selected objects. If you apply this modifier to all objects in the scene, the total polygon count can reach half a million. To quickly apply a modifier to different smoothing levels, use the keyboard shortcuts Ctrl + 1, Ctrl + 2, Ctrl + 3, and Ctrl + 4. It is important to note that using modifiers results in a complete recalculation of the object's geometry, as a result of which the effect of applying identical meshes disappears.

Note: This text serves as an important reference point for understanding the key aspects of the topic discussed. It emphasizes the significance of the data presented and its impact on further research. Pay attention to the main points that require special attention and analysis. These aspects may affect the practical application and interpretation of the results. Make sure you take into account all the nuances to avoid misunderstandings and ensure the accuracy of the information.

To apply a modifier to all objects, follow these steps: First, apply the modifier to the active object. Then, select the remaining objects to which you want to copy it by pressing A. Then, press Ctrl + L and select Copy Modifiers from the menu that opens. This process allows you to effectively transfer modifier settings to multiple objects at once, significantly simplifying your project work.

The reverse process works similarly: if you delete a modifier from the active object and use the Copy Modifiers function, you can transfer the settings to all selected objects. This method allows you to effectively manage modifiers and save time when editing several objects at the same time.

A similar operation can be performed inside an object. To do this, cancel the modifier with the keyboard shortcut Ctrl + Z and go to edit mode. Select all the polygons by pressing the A key, then open the tool menu with the right mouse button or the W key if you have the selection assigned to the right mouse button. Choose the Subdivide option. A tab with the same name will appear in the lower left corner of the viewport. Open it and set the Smoothness value to 1 and the Number of Cuts to (Number of Cuts) by 4. This way, you can effectively divide polygons and improve the detail of the model.

This produces a similar effect to applying the modifier with the keyboard shortcut Ctrl + 4, but the scene now only contains 150 polygons. Even if you continue duplicating with the keyboard shortcut Alt + D, the face count will remain the same. This allows us to optimize performance and simplify working with models in 3D graphics.

If each of the 2156 objects had its own mesh, this scene would have about 1 million polygons. Screenshot: Leon Balbury for Skillbox Media

You can select any object and enter edit mode to make changes as desired using the methods from the second lesson. Any changes you make will automatically be applied to all other objects, since they share the same mesh. This allows you to effectively edit and optimize objects, while maintaining a unified style and harmony in the project.

Objects after manipulations in Edit Mode. Screenshot: Leon Balbury for Skillbox Media

If you select one of the objects in Object Mode, in the Transform tab, under the Element section, you can set unique parameters for position, rotation, scaling, and dimensions along any axis. In this case, changes made to the transformation will not affect other objects, preserving their original characteristics.

Transformation of one object. Screenshot: Leon Balbury for Skillbox Media

When creating large-scale scenes, it is possible to use only a single mesh, which significantly optimizes resource costs. For example, even with 17,248 objects in the scene, the total polygon count is only 150. If a separate mesh were used for each object, the total polygon count would reach about 8 million. This example demonstrates how optimization can significantly improve the efficiency of working with 3D scenes and reduce the load on the system.

This method similarly applies to entire collections, which we discussed in the first lesson. For example, if you have a collection of eight different house models that you want to duplicate, standard copying will significantly increase the polygon count in the scene. However, if you right-click the collection and select the «Instance to Scene» option, (Instance to Scene), you can duplicate a group of models without increasing the geometry. You can also perform this operation via the Add menu (Shift + A) and select Collection Instance. This will keep the polygon count the same, which will help optimize your scene and speed up your work.

Note: When using this text, please be aware that it may contain important information that you are advised to review. All data provided is current at the time of publication and is subject to change over time. We recommend regularly checking sources and updates to stay informed about the latest changes. Pay attention to possible links to additional resources that will help deepen your understanding of the topic.

Please note that collections may overlap. If new objects are not visible at first glance in the scene, be sure to check the project structure - the copied collections will be displayed there. This will help you better organize your workspace and avoid confusion with scene elements.

To separate a duplicated collection into individual objects, select it and go to the Apply menu (Ctrl + A), then choose the Apply — Make Instances Real option. This process will convert the duplicates into independent objects, which will simplify further work with them and improve the organization of your project.

Saving polygons significantly impacts program performance and the rendering process. This is critical when creating animation, as optimizing polygons can reduce the rendering time of each frame by several minutes. Effective polygon management not only speeds up work in the program but also improves the overall result, allowing you to create higher-quality visualizations without wasting time.

Now let's consider the possibility of modifying objects in Blender not individually, but using built-in tools and Python scripts. This will significantly simplify the editing process and automate tasks related to modeling and animation. Using Python scripts, you can create more complex and efficient algorithms for mass modification of objects, which will significantly save time and improve the quality of work in Blender.

Randomization with Blender Tools

Return to object mode and select all the objects. Make sure that you do not capture the camera and light source when selecting. This is important for correct work with scene elements and preventing unwanted changes.

Blender has a command search function, accessible by pressing F3. With it, you can quickly find and use the Randomize Transform command. If you have a lot of objects in your scene, it may take a little time for the result to load.

A tab appears in the lower left part of the screen that allows you to randomize the position, rotation, and size of objects along all three axes. Let's look at the Rotation parameter, for example. By setting the maximum value in the first field to 180, each object will receive a unique rotation angle along the X axis, ranging from 0° to 360° (-180° to 180°). We'll also experiment with the Scale parameter, setting it to 5. This will cause each object to change its scale to a random value between 1 and 5. If there are many objects in the scene, it may take some time to process them.

The result of changing the rotation of objects along the X axis (180°) and their scale (5). Screenshot: Leon Balbury for Skillbox Media

The problem users face when performing this operation is that a large number of objects in the scene leads to a long processing time. Using Python in Blender can significantly optimize the randomization process, allowing you to significantly reduce the time spent manipulating objects. The use of scripts and automation of tasks with Python opens up new possibilities for increasing the efficiency of working in Blender.

Randomization with Python

Let's go back to the step before randomizing objects using the Randomize Transform function. We'll start by selecting only the objects we plan to randomize in a separate collection, in this case, cubes. Rename the collection, for example, to Cubes. This name will later be conveniently used in code as a collection identifier.

To launch the Python console, move the cursor to the bottom edge of the viewport window and gently drag it upward. In the window that opens, select "Editor Type" and then select "Python Console." This will allow you to interact with Python directly, entering commands and receiving results in real time.

Randomization in Python is accomplished through the random module. First, import this module into your workspace using the import command. After executing this command, Blender will have access to the functionality of the random module. This module is bundled with the version of Python used by Blender, allowing the program to seamlessly use its methods for generating random numbers and other operations related to randomization.

The random module is a comprehensive class containing numerous methods and subclasses. To explore its contents, type random at the prompt, then use the dot key to access the module's internal hierarchy. Then press Tab (or Ctrl + Space in versions prior to 2.82a) to display the available methods and subclasses. This will allow you to quickly find the functions you need for working with random numbers and other elements, ensuring the effective use of the random module's capabilities.

A note is an important element that can contain additional explanations, comments, or recommendations on a specific topic. It serves to clarify information and helps the reader better understand the context. Notes are often used in training materials, scientific articles, and documentation where it is necessary to emphasize key points or provide additional information.

When writing notes, it is important to maintain clarity and conciseness. They should be easy to perceive and not overloaded with unnecessary details so as not to distract from the main information. Proper formatting of notes and their competent use can significantly improve the quality of content and increase its value to readers.

Considering all these aspects, notes are an integral part of high-quality content that helps effectively convey information to the target audience.

The auto-complete feature in development environments helps speed up the process of entering commands. Using the Tab or Ctrl + Space keyboard shortcut, you can quickly complete the entered text. For example, if you type «obj» and press Tab, the program will automatically convert it to the word «object». This saves a lot of time and makes it easier to work with code, especially when writing long identifiers. Use this feature to increase productivity and reduce typing errors.

To work with random number generation in Python, we will need the randint() method. Type random.randint() in the console and press Tab (in versions before 2.82a, use Ctrl + Space) to get information about this method. This method allows you to generate random integers in a specified range, which makes it useful for various tasks related to randomness, such as games or simulations.

This method generates a random integer in the specified range, including its extremes. For example, we will enter the values ​​0 and 100 in parentheses, separated by commas, and then press Enter. This will generate a random number between 0 and 100, which is useful in various scenarios such as games or statistical analysis.

The method generates the number 39 (your result may vary). If you refresh the command by pressing the ↑ (up) key and press Enter again, a new number between 0 and 100 will be generated. The result will change each time you enter the command. However, repetitions are also possible, since the random algorithm makes the result unpredictable.

Blender's randint() method allows you to set random scale values ​​and other parameters for objects, greatly simplifying the process of creating unique scenes. Blender uses the bpy module to work with objects, which is automatically available in the Python console upon startup. This means that there is no need to import it separately using the import command. Using random values ​​can be useful for generating a variety of effects and speeding up your 3D modeling workflow.

The bpy module is a key tool for interacting with the Blender interface. It allows users to manage various aspects of the application. Specifically, the app component encompasses all functions related to working with the application, while the context contains information about current elements, such as the active object, scene, window, and other interface elements. Thus, the bpy module significantly simplifies the workflow in Blender, allowing users to more efficiently configure and manage their projects.

To work with a project in Blender, we need the data class. This class stores all the current project data, which is also available in the Blender file. It includes information about collections, objects, cameras, lights, meshes, and other elements, allowing for efficient management of project contents. Using the data class provides convenient access to key data needed for modeling and animation in Blender.

Location of the Blender File tab. To return to the previous menu, select View Layer. Screenshot: Leon Balbury for Skillbox Media

To get information about objects, not meshes, you need to enter the path to the class containing these objects in the line. This process allows you to access detailed data about each object, which is important for working with them correctly in your project.

After pressing the Tab key (in versions prior to 2.82a, Ctrl + Space), the program will provide an extensive list of the names of all objects in the project. To search for a specific object, you need to specify the path to the class, then add square brackets and enter its exact name in quotation marks (double "" or single »). This will allow you to quickly and efficiently find the desired elements in a large project.

Note: This section contains important clarifications and comments that may be useful for understanding the topic. Please pay attention to the details and recommendations below. These notes will help you better understand the material presented and avoid possible misunderstandings. Read them carefully to get the most out of the content.

When specifying a name, it is important to take into account the case of the letters, as uppercase and lowercase letters matter. For example, "Cube" and "cube" represent different objects. This is important for correctly working with data and searching for information.

When you press Enter, if an object with the specified name exists, it will be displayed in the line. Otherwise, the program will generate an error.

We set up a loop to iterate over objects using the for command. To do this, we use the following construction: for variable_name in object_list. In this context, variable_name will take the value of each element from the object list in turn, which allows you to efficiently process data and perform the necessary operations on each element. This approach ensures simplicity and readability of the code, which is an important aspect of programming.

This construction translates as "for each object of all objects in the project:". Note that it ends with a colon. In this context, ‘object’ is the name of the variable (any other word can be used instead of ‘object’) that will successively receive the value of each object from the bpy.data.objects class. Different operations can be performed on each of these objects.

Note: This text contains important information that you should take into account. Make sure you read these guidelines to avoid potential misunderstandings. Proper understanding and application of the information provided will save you time and resources, and improve your efficiency.

The word «object» is a reserved word in Python and has a key meaning in the programming language. Using this term as a variable name may lead to losing access to its original value within your program. To avoid such problems, it is recommended to use other words or their abbreviations for naming variables, such as «ob», «obj» and similar variations. This will help keep your code readable and prevent potential errors.

Enter the command for object in bpy.data.objects: and press Enter. Notice that the next line is automatically indented. This indentation tells the program that the subsequent line belongs to the loop body and will be executed for each object. Now let's create a variable that will receive a random value.

scale is the name of the variable, which can be replaced with any other word that will be used later to denote the value of this variable. Choosing a variable name plays an important role in coding, as it should be intuitive and reflect the essence of the data you are working with. Proper variable naming improves code readability and maintainability, which is an important aspect in software development.

The random module in Python provides various functions for generating random numbers, and one of the most popular methods is randint. The randint function allows you to get a random integer within a specified range. This method is useful in various applications such as games, modeling, and statistical analysis. Using randint, developers can easily generate random values ​​for their projects, adding an element of unpredictability and interactivity.

The range of random values ​​is from 5 to 100.

Adjusting the result obtained using the randint() method consists of dividing this result by 100. This approach allows you to normalize the values ​​​​obtained from the random number generator and provides more convenient work with them in the context of further calculations or data analysis.

To solve our problem, we need to set the range of random values ​​​​from 0 to 1. Since the randint method only works with integers, we will choose a range from 5 to 100 and then divide the resulting random value by 100. As a result, we will get a number in the range from 0.05 to 1, where 5/100 is equal to 0.05, and 100/100 is equal to 1. This approach allows you to efficiently generate values ​​​​suitable for various algorithms and calculations.

The next step is to set the obtained value as the object's size. Confirm the execution of the previous line by pressing Enter. Note that the same indentation is maintained at the beginning of the new line, indicating that the loop body description continues. Enter the following command:

Object is a variable used in the for object in bpy.data.objects statement. It represents each of the objects present in the scene.

When setting the scale of an object in 3D graphics, it is important to note that the scale value is specified in parentheses three times, separated by commas. In the Transform panel, you can see that the Scale of each object is determined by three axes: X, Y, and Z. Therefore, the command object.scale = scale will not work, since it specifies only one value, while three different ones are required. To correctly set the scale variable value for all three axes, you should write it in parentheses three times, separated by commas: object.scale = (scale, scale, scale). This will ensure the correct scaling of the object in 3D space.

Confirm the line and delete the indents at the beginning of the next line, since no additional commands are required. Then press Enter again. Wait a little, and we will get the desired result.

The obtained result. Screenshot: Leon Balbury for Skillbox Media

All objects in the scene have different sizes. If we run the loop through the objects again by simply copying three lines of code, the scales of the objects will change randomly, and the scene will take on a new appearance. This process allows us to dynamically change the visual representation of the scene, which can be useful for creating unique effects and variety in a project.

The data processing process is noticeably faster compared to using Randomize Transform. To accurately measure the processing time, we will create a new script based on the previously developed one. This will allow us to obtain more accurate results and optimize our work with data.

To optimize our work with the viewport window, move the cursor to the upper right corner and drag it to the left to split the window. Then, select the Text Editor editor type in the new window. This will allow you to write the necessary script more conveniently and quickly than doing it in the Python console.

First, click the +New button. Before copying the commands specified in the previous step, you need to re-import the required modules, since the text editor has no information about the operations performed in the Python console. We import modules using the import command, separating them with a comma. This will allow the editor to access the necessary functions and libraries for further work with the code.

Let's look at the main modules again. The bpy module is responsible for interacting with the Blender interface, the random module is used to generate random numbers, and the time module allows you to track the execution time of operations. It is important to note that, unlike the Python console, where some modules, such as bpy, are imported automatically at startup, in the text editor all modules must be added manually. This knowledge is important for working effectively with Python in Blender and optimizing your scripts.

Next, we will define a function that will execute a specific part of the code. A function is a block of code that can be called multiple times, which makes it a convenient tool for simplifying programming. A function is indicated by parentheses at the end of its name. Before using a function in your code, you need to define it. To do this, use the following construct:

A programming function definition begins with the def keyword (from the English "define"). This keyword signals to the compiler or interpreter that a function definition is to follow. Functions are an important element in programming languages ​​because they help structure code, simplify its reuse, and improve readability. The def keyword is the primary way to declare a function, followed by the function name and its parameters, if any. Properly defining and using functions contributes to more efficient and organized code.

The random_scale function is designed to generate random scales. It is used in various applications that require adaptive adjustment of the sizes of objects or interface elements. Its main purpose is to create changeable and dynamic visual effects, which is especially important in game development and web design. Proper use of the random_scale function can significantly enhance the interactivity and engaging user experience. It is important to remember that when calling this function, you must consider the parameters that affect the final result in order to achieve the desired effect.

Parentheses in function syntax are an important element that can be either empty or contain parameters. Parameters specified in parentheses are typically used within the function body to perform specific operations or calculations. Proper use of parentheses and parameters in functions is a key aspect of programming, ensuring the flexibility and efficiency of code.

The colon (:) marks the beginning of the function body. This symbol is used in programming languages ​​to separate the function header from its content, allowing you to clearly identify where code execution begins. Proper use of the colon is key to structuring and organizing your code, making it easier to read and understand.

After you press Enter, the editor will automatically indent it. You can also indent it by pressing the Tab key or four spaces. Indentation in Python plays a key role because it determines whether lines belong to the same block of code, such as a function body or a loop. Proper use of indentation ensures correct program execution and makes the code easier to read.

Before the main part of the function, we will record the execution time. To do this, we will create a variable t1 and assign the current time to it using the perf_counter() method from the time module. This will allow us to accurately measure the function's execution time and optimize the code's performance.

A method is a function that belongs to a specific class in object-oriented programming. To access a method, you must specify the name of the class it belongs to and use a period to separate it from the method name itself. It is important to note that the keyword «def» is only used when defining a new function. To call an existing method, simply specify its name with opening and closing parentheses.

Now you need to copy and paste the loop that is responsible for randomly adjusting the scale of all objects. This loop was previously implemented in the console.

It is important to remove the extra dots that automatically appeared when copying from the console, and to set the indentations correctly. The loop body should be separated by a new indentation for better readability. The next line after the loop with the t2 variable records the function execution time. Proper code formatting improves its comprehension and facilitates further work with it.

To determine the duration of the entire process, you need to subtract the value of t1 from t2 and display the obtained result. For this, we use the print() command. This is a built-in Python method that allows you to output text and numeric information to the system console. It should not be confused with the Python console. The system console can be opened through the tab «Window» — «Show/hide system console» (Window — Toggle System Console).

This method is suitable for Windows users. For macOS or Linux users, you should launch Blender via the terminal by specifying the full path to the blender-launcher.exe file. This will cause the terminal to function as a system console, allowing you to monitor processes and display error messages.

In order to display the time difference between the start and end of the function in the console, it is necessary to perform the calculation inside the brackets. This will allow you to accurately determine the time interval spent on executing the function.

At the moment, the function is presented solely as a statement and will not be executed automatically when the script is run. To activate it, you need to call it. We separate the written function with a blank line, and then in the next line we indicate the name of the random_scale() function without the def prefix, indents and a colon, but with parentheses at the end. This will call the previously defined function.

When the script is run, each object in the scene will be assigned a random value for the scale parameter. The system console will display information about the time spent on executing this operation. To run the script, simply click the play button in the upper-right corner of the editor or use the Alt + P keyboard shortcut.

After completing the operation, open the system console to analyze the results. In this case, the function execution took 0.34 seconds. This time allows you to evaluate the code's efficiency and identify potential performance bottlenecks.

A note is an important addition to the main text that can contain clarifications, explanations, or additional information. In the context of writing articles and website content, notes play a significant role in improving the reader's understanding of the material. They can help avoid misunderstandings and provide useful information that was not included in the main text. Effective use of notes contributes to the quality of content and improves its readability. When creating SEO-optimized text, it is important to consider that notes can also contain keywords and phrases, which increases the visibility of the page in search engines. Properly formatted notes improve the structure of the text and facilitate navigation, which, in turn, can positively impact the user experience.

This script is designed to work with all objects in the project. At the beginning of the chapter, we mentioned a collection with cubes called Cubes. To modify objects only in this collection, you should replace the fragment bpy.data.objects with bpy.data.collections[‘Cubes’].objects, where ‘Cubes’ is the name of the desired collection. This approach allows for more precise control of objects, ensuring convenience and efficiency in working with data in Blender.

To summarize, using Python, we were able to randomize the scale of 17,248 objects in just a third of a second. This demonstrates how basic programming skills can significantly optimize processes and speed up operations compared to traditional Blender tools. Using Python in 3D graphics opens new horizons for increasing efficiency and productivity in design.

In the fourth part of our guide, we'll delve into the basics of animation and discuss various methods for implementing it. You'll learn the key principles of animation, as well as techniques that will help you effectively reproduce animated effects. This information will be useful for both beginners and experienced developers looking to improve user interaction through animation.

Check out other materials in this series.

  • Blender Tutorials: Interface, Navigation, Simple Operations
  • Blender Tutorials: Modeling Basics
  • Blender Tutorials: Animation Basics

3D Artist Profession

By taking this course, you will learn Autodesk Maya, Blender, Houdini, Substance Painter, and Photoshop from scratch to a professional level. Learn 3D modeling and add more than 20 practical works to your portfolio, and become a sought-after 3D artist. In a year, you will master a profession in demand in the film and gaming industries. Pictured: work by course participant Dmitry Danilov.

Learn more