Working with sharp edges using Blender Python API

In Blender, we can mark the edges of the mesh as sharp so that they remain sharp and do not become smooth even when we enabling smooth shading. This can be done manually by selecting the desired edges and pressing the Edge – Mark Sharp items in the main menu. Edges can also be marked as sharp using the Blender Python API.

We can set edges as sharp and remove this mark using the API both for the base mesh in the scene and using the bmesh module.

Working with sharp edges through the base mesh

We can access the properties of the edges of the base mesh in object mode, so switch the mesh to “OBJECT” mode.

To get a list of all the edges already marked as sharp, loop through all the edges of the mesh and check the “use_edge_sharp” property for each one.

If this property value is True, the current edge is marked as sharp and information about it will be output to the console.

To mark the desired edges as sharp, first select them, and then loop through all the edges of the mesh and set the “use_edge_sharp” property for the selected edges to True.

After all, return the mesh to “EDIT” mode.

Working with sharp edges in bmesh object

Create a bmesh object and transfer the data from the current active mesh into it. To ensure that the edge indices in the bmesh object correspond to the indices of the base mesh, also execute the ensure_lookup_table() command.

bmesh edges (BMEdge) do not have a property to mark edges as sharp, but they have a “smooth” property that has the opposite meaning. If the “smooth” property value is True, then the edge is common, not sharp. If “smooth” value is False, then the edge is marked as sharp.

Loop through the bmesh edges and output those edges, that are “not smooth”.

To mark selected edges as sharp, we simply need to set the smooth value of those edges to False.

After all, move the edited data back to the base mesh and free the bmesh object.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments