Create a list of all of a mesh's individual pieces?

Say I’ve got 3 cubes that have been “joined” into the same mesh… but are still 3 distinct “pieces”. Is there an easy way to create a list of each distinct “piece” of a mesh, itself being a list of polygons.

I’d rather not rely on using bpy.ops.mesh.separate(type=‘LOOSE’) unless I really really have to. (I absolutely HATE using those ops functions… they seem so damn messy… Why can’t I just pass it a mesh and get a mesh returned, instead of having to worry about what’s selected, and what isn’t???)

Operators represent user actions, and they run in a certain context (certain area type, mouse location, selection state etc.). From my understanding, it is necessary to be this way to allow for undo/redo actions.

It’s not an API like you might expect, which takes in arguments and returns a reference to the resulting mesh. The bmesh module does kinda work like that, but not all operators are also available in that module.

In your case, I would use the operator (maybe using a temp copy of the mesh). The underlaying code to separate the mesh parts will run in C, so performance is good. You also don’t have to come up with your own algorithm to tell mesh pieces apart.

Ah yes, I was afraid of that. Well, thanks for the tips!

It’s a shame that the bmesh module doesn’t have as good of functionality as the built in mesh tools.