The previous tutorial allowed us to create a polygon. However, in 3D modeling it is extremely rare that one builds an object with only one polygon. Generally, it consists of a complicated unit, a mesh, or a lattice. It is obviously not possible to consider creation of each polygon "by hand". Especially, when it is known that a Blender mesh can contain more than 65000 polygons. It is for this reason, that the power of the programming language will become apparent, in the possibility of automating this operation. To accomplish this, we need to know how to build an iterative loop in Python. To create an iterative loop in Python An iterative loop could correspond to the
following pseudo code:
With Pascal or the Modula languages, this
would produce:
In the C language:
In BASIC:
In these languages, the loops proceed between boundary markers which are clearly defined: limits concerning the number of possible iterations, which as well, limits the number of times that the commands comprising the body of the loop are performed. These limits be brackets or keywords like " begin/end " or " for/next" , but the result is one and the same. Alas, Python is optimized, one can even say that it was born to work with lists. An iterative loop will take a list as limits. This means that the loop will begin on the first element from the list, then jump to the second element and so on. This operation will be carried out at least once for each element of the list, until the end of the list is reached. In Python:
Moreover, this_variable really
is
the actual element of this_list. If this_variable
is processed in the body of the loop, this amounts to working directly
on the element in question. ie. Besides the element being involved in the
loop's control mechanism, it may also be involved in the work being performed
in the loop's body.
It is not the intention of this tutorial to show the undeniable advantages of proceeding in this way. However, it is clear that it may come as some what of a surprise, especially if you already have some previous programming experience with other languages. Although, the above is a "step in the right
direction" there are a few more obstacles to overcome, because to
work EASILY with our mesh, we need to reach values which correspond
to lines and to the positions in these lines, in fact cells in a bidimensional
table ( 2D spaces, x and y coordinates , nothing too difficult to understand).
|