Creating
the faces is not much more difficult than that of the vertices. However,
it is necessary to observe which vertices will have to
be assembled and in which order. We start, once again, by using the
same variables n , i and
j
.
Though, this time, i and
j
represent
the row and column position of the faces, respectively. As before, we proceed,
one line at a time.

One quickly realizes that all the faces can
be filled in, while varying i and j between 0.0 and n
- 1. The remainder is only a matter of filling in the blanks. Well, almost;
it is also necessary to transform the value n into an integer ;
since the indices of a list can only be integers. The following method
is perhaps not very elegant, but it does illustrate some techniques which
we have already discussed :

n0=len(range(0,
n))

Python offers a more succinct conversion function,
to convert the type as follows:

n0=int(n)

i=0, j=0

0

1

2

3

4

5

6

7

8

i=0, j=1

0

1

2

3

4

5

6

7

8

i=1, j=0

0

1

2

3

4

5

6

7

8

i=1, j=1

0

1

2

3

4

5

6

7

8

Python script source:

# [ snip... ] # we resume at the exact location in the
source # where we left off from in the previous
part.

# Translate the value of n from a floating
point # (decimal) value to an integer (whole
number). # n0=len(range(0, n))n0=int(n)

for i in range(0, n-1): # The first
subroutine begins here, # with
four spaces of indentation for j in
range(0, n-1):
# The second loop begins here,
# with eight spaces of indentation
f=NMesh.Face()
f.v.append(me.verts[i*n0+j ])
f.v.append(me.verts[i*n0+j+1 ])
f.v.append(me.verts[(i+1)*n0+j+1 ])
f.v.append(me.verts[(i+1)*n0+j ])
# After specifying the vertice co-ordinates for the
# face, it is added to the faces list of " me ".
me.faces.append(f)
# End of the internal loop # End of
the external loop