What are bmesh.loops?

Hello! Somebody made me notice that now, with bmesh, in addiction of vertices edges and faces, we also have loops in the bmesh structure. Actually I can’t ask him explanations about that, so I would ask you if you know something about that. Does bmesh.loops have something to do with modeling? Could it allow me to find open mesh borders, ngons borders e things like that, or did I misunderstood everything?

Thankyou for explanations! :slight_smile:

1 Like

Do not know exactly, but you may ‘play’ like this:
Make a plane, and subdivide once
select an edge and subdivided once toe
go to object mode
open a Python-console.
pData = bpy.context.active_object
f0 = pData.polygons[0]
f0.loo (type now Ctrl-space) to see loop options and explore!

It looks like this: e.g loop.indices shows HOW much vertices the polygon has
loop.total (as it says: the total number of vertices)
loop.start: where to start ???

and this I got, with f0 a polygon with 5 vertices
>>> for i in f0.loop_indices: print(f0.vertices[i])

8
9
6
1
4


Looks good :wink:

I’ve just started writing scripts to use bmesh and I just asked myself this very question! I found this:

http://wiki.blender.org/index.php/Dev:2.6/Source/Modeling/BMesh/DocMirror

This documentation and its sub-module documentation are my current sources of knowledge on working with bmeshes:

http://www.blender.org/documentation/blender_python_api_2_64_1/bmesh.html

A loop represents a single loop of edges around a face, along with links to various details such as vertices, colors, UVs, etc. As I understand it, a loop is a utility data structure - it just collates existing mesh data into one place rather than adding anything new. As such they don’t require any management on your part if you’re creating mesh data in code.

Note that the module documentation is a bit weak at the moment, there seems to have been some sort of problem with the generation of the API docs so there is some incorrect information in there (i.e. all the properties marked as read only which is not the case, spurious function parameters).

a loop as per-face vertex data. Imagine a cube: all of its 8 vertices are shared among the 6 faces, every vertex is part of 3 different faces.

But now imagine, you wanna paint one face red, another blue. You can only store one color per vertex, so either red or blue (or mix it to purple). But if you wanna have two different colored faces separated with a hard edge, you need loops (per-face vertex data) to store the color information.

So loops are used by a single face, while vertices are shared. Loops are required, or you couldn’t texture faces with different images etc.

If you sum up all vertices each face uses, you will get the loop count. A cube has 6 faces, and each face has 4 vertices, therefore it has 24 loops.

2 Likes

Ahh, I see. Randomly I was actually wondering how they did the per-face material thing earlier today, but didn’t but two and two together.

Thanks.

thankyou all, so loops don’t help me to recognize a loop or a border like this. Thay have just to do with poligons.

Attachments


sorry tested little csript in lastest SVN on console and it gives an error on the second line

anyone know show to make it work !

also how do you make the vert number appears ?
any link to a working script fo this effect ?

thanks

To activate e.g. the outer of inner loop (inner your picture) use in edit-mode Alt-RMB
outer loop Alt RMB and Shift Alt RMB (3 times)

Could it allow me to find […] ngons borders e things like that

A single ngon border = the border/outline of a polygon. Yes, if you take one polygon and loop over its loops, then you get will get all verts of that polygon (loop.vertex_index gives you the vert#)

No, loops don’t store “edge rings”, but you can find the word “loop” in edit mode in blender used for such things, it is something different though.