Fix T70617: mesh.from_pydata() misses first edge if there are faces
authorCampbell Barton <ideasman42@gmail.com>
Thu, 10 Oct 2019 00:08:17 +0000 (11:08 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 10 Oct 2019 00:16:51 +0000 (11:16 +1100)
release/scripts/modules/bpy_types.py
source/blender/blenkernel/intern/mesh_validate.c
source/blender/editors/mesh/mesh_data.c

index 76c495c078deb5b609892a1cd9ab58f0613267c9..6cb9600b9b44588315c59b3efb04bfb92180b256 100644 (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):
index c8e7553207522f7597f78b5063493ad7c7a4d451..fa03aec3e082f185c54cc1dbd09a145dff1ba85f 100644 (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;
+    }
+  }
 }
 
 /**
index 569994bead1c8224ad2df5c5289b4b489ddd9d2b..a0d424e083c452c01fc87c529f6a2babcf38b3b9 100644 (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);