Fix T70617: mesh.from_pydata() misses first edge if there are faces

This commit is contained in:
Campbell Barton 2019-10-10 11:08:17 +11:00
parent dc2cd2d0dc
commit 5910f9f9e9
Notes: blender-bot 2023-02-14 06:42:54 +01:00
Referenced by issue #70617, Python mesh.from_pydata() misses first edge if there are faces
3 changed files with 19 additions and 14 deletions

View File

@ -441,11 +441,6 @@ class Mesh(bpy_types.ID):
When an empty iterable is passed in, the edges are inferred from the polygons.
When non-emtpy, either:
- Edges must be provided for all polygons.
- Edges must be calculated afterwards using :class:`Mesh.update` with ``calc_edges=True``.
:type edges: iterable object
:arg faces:
@ -481,11 +476,15 @@ class Mesh(bpy_types.ID):
self.polygons.foreach_set("loop_start", loop_starts)
self.polygons.foreach_set("vertices", vertex_indices)
# if no edges - calculate them
if faces and (not edges):
self.update(calc_edges=True)
elif edges:
self.update(calc_edges_loose=True)
if edges or faces:
self.update(
# Needed to either:
# - Calculate edges that don't exist for polygons.
# - Assign edges to polygon loops.
calc_edges=bool(faces),
# Flag loose edges.
calc_edges_loose=bool(edges),
)
@property
def edge_keys(self):

View File

@ -1619,6 +1619,12 @@ void BKE_mesh_calc_edges_loose(Mesh *mesh)
for (int i = 0; i < mesh->totloop; i++, ml++) {
mesh->medge[ml->e].flag &= ~ME_LOOSEEDGE;
}
med = mesh->medge;
for (int i = 0; i < mesh->totedge; i++, med++) {
if (med->flag & ME_LOOSEEDGE) {
med->flag |= ME_EDGEDRAW;
}
}
}
/**

View File

@ -880,14 +880,14 @@ void MESH_OT_customdata_custom_splitnormals_clear(wmOperatorType *ot)
void ED_mesh_update(Mesh *mesh, bContext *C, bool calc_edges, bool calc_edges_loose)
{
if (calc_edges_loose && mesh->totedge) {
BKE_mesh_calc_edges_loose(mesh);
}
if (calc_edges || ((mesh->totpoly || mesh->totface) && mesh->totedge == 0)) {
BKE_mesh_calc_edges(mesh, calc_edges, true);
}
if (calc_edges_loose && mesh->totedge) {
BKE_mesh_calc_edges_loose(mesh);
}
/* Default state is not to have tessface's so make sure this is the case. */
BKE_mesh_tessface_clear(mesh);