Custom vertex and edge layers without BMesh

I just discovered the concept of custom layers (such as BMesh.edges.layers.int[…]). It seems well designed and perhaps will be very useful for my script (export paper model).

However, is it necessary to use BMesh conversion to access that data? The polygon layers are accessible through the classic Mesh object (Mesh.polygon_layers_int), that’s why I don’t ask about them. I would prefer using Mesh for simplicity, if possible.

Before I post this as a bug, I’d like to bump this thread: is there really no way how to access custom edge layers in the classic Mesh structure?

I’d like to use one for real-time drawing, where converting to BMesh on every call seems somehow wrong. Or am I mistaken, is BMesh convertion a constant-time operation?

there’s no access to the custom vert/edge/loop data in standard API, so you need to use the bmesh module. But you can use bmesh.from_edit_mesh(), to gain direct access to the mesh data (there’s no copy made of the mesh and converted to a special “bmesh”)

Well, that partially solves the problem, but not fully. The function bmesh.from_edit_mesh is quick, but it works in edit mode only and switching between object <-> edit mode appears to be too slow for viewport drawing. So is using bmesh.new -> BMesh.from_mesh.

So, thank you, I’m glad that I can reach my objective in edit mode. However, drawing in object mode would be useful as well, it usually has a less cluttered viewport.
And I see no reason for having only Mesh.polygon_layers_(x) in the API: polygons seem in no way superior to vertices and edges to me…?

Well yeah, the distinction between Mesh and Editmesh is frustrating in certain situations like yours. I wonder myself why there’s polygon_layers but no vertex_layers etc., can’t see a reason to have one but not the other.