[Bf-blender-cvs] [d09646a40b1] blender-v2.82-release: Fix T73095: Edit Mode Overlay Linked Mesh

Jeroen Bakker noreply at git.blender.org
Tue Feb 4 07:49:41 CET 2020


Commit: d09646a40b1928308025d8ceb2c2d505651fc9a4
Author: Jeroen Bakker
Date:   Mon Feb 3 08:16:38 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBd09646a40b1928308025d8ceb2c2d505651fc9a4

Fix T73095: Edit Mode Overlay Linked Mesh

When using duplicate linked meshes, objects that are not in edit-mode will be drawn as
it is in edit mode, when another object with the same mesh is in edit mode.
This will not be the case when one of the objects are influenced by modifiers. The change
reflects more how it was done in Blender 2.79.

The current change introduces a draw manager method that checks in detail who is responsible
for the drawing (render engine or overlay engine). If the edit mesh is not the original or
the object that is drawn doesn't draw the original mesh the object will be drawn by the render
engine.

Known Limitation of this patch is that the rendering outside edit mode doesn't reflect the
latest changes until the user switches between object and edit mode. When there are no
modifiers in use, the updating is done immediately.

IMO this would be sufficient for blender 2.82, it also fixes parts of T72733.
The updating of the surface batches requires more development and is
post-poned for now.

Reviewed By: fclem, brecht

Differential Revision: https://developer.blender.org/D6737

===================================================================

M	source/blender/draw/engines/overlay/overlay_engine.c
M	source/blender/draw/engines/overlay/overlay_wireframe.c
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/intern/draw_manager.c

===================================================================

diff --git a/source/blender/draw/engines/overlay/overlay_engine.c b/source/blender/draw/engines/overlay/overlay_engine.c
index 59a03d10fbe..c83b3487db0 100644
--- a/source/blender/draw/engines/overlay/overlay_engine.c
+++ b/source/blender/draw/engines/overlay/overlay_engine.c
@@ -179,7 +179,7 @@ BLI_INLINE OVERLAY_DupliData *OVERLAY_duplidata_get(Object *ob, void *vedata, bo
 
 static bool overlay_object_is_edit_mode(const OVERLAY_PrivateData *pd, const Object *ob)
 {
-  if ((ob->mode & OB_MODE_EDIT) && BKE_object_is_in_editmode(ob)) {
+  if (DRW_object_is_in_edit_mode(ob)) {
     /* Also check for context mode as the object mode is not 100% reliable. (see T72490) */
     switch (ob->type) {
       case OB_MESH:
diff --git a/source/blender/draw/engines/overlay/overlay_wireframe.c b/source/blender/draw/engines/overlay/overlay_wireframe.c
index d3c513e5963..e39f51aa606 100644
--- a/source/blender/draw/engines/overlay/overlay_wireframe.c
+++ b/source/blender/draw/engines/overlay/overlay_wireframe.c
@@ -154,7 +154,7 @@ void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata,
     }
   }
 
-  const bool is_edit_mode = BKE_object_is_in_editmode(ob);
+  const bool is_edit_mode = DRW_object_is_in_edit_mode(ob);
   bool has_edit_mesh_cage = false;
   if (is_mesh && is_edit_mode) {
     /* TODO: Should be its own function. */
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 8037bd03383..ddaf851324d 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -617,6 +617,7 @@ void **DRW_duplidata_get(void *vedata);
 
 /* Settings */
 bool DRW_object_is_renderable(const struct Object *ob);
+bool DRW_object_is_in_edit_mode(const struct Object *ob);
 int DRW_object_visibility_in_active_context(const struct Object *ob);
 bool DRW_object_is_flat_normal(const struct Object *ob);
 bool DRW_object_use_hide_faces(const struct Object *ob);
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index d1823292585..1dcc605fc50 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3449,7 +3449,7 @@ void drw_batch_cache_generate_requested(Object *ob)
   const bool use_hide = ((ob->type == OB_MESH) &&
                          ((is_paint_mode && (ob == draw_ctx->obact) &&
                            DRW_object_use_hide_faces(ob)) ||
-                          ((mode == CTX_MODE_EDIT_MESH) && BKE_object_is_in_editmode(ob))));
+                          ((mode == CTX_MODE_EDIT_MESH) && DRW_object_is_in_edit_mode(ob))));
 
   struct Mesh *mesh_eval = ob->runtime.mesh_eval;
   switch (ob->type) {
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 167e48e9c2d..a1eb9b57629 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -1076,13 +1076,7 @@ void DRW_mesh_batch_cache_create_requested(
     BLI_assert(me->edit_mesh->mesh_eval_final != NULL);
   }
 
-  const bool is_editmode =
-      (me->edit_mesh != NULL) &&
-      (/* Simple case, the object is in edit-mode with an edit-mesh. */
-       (ob->mode & OB_MODE_EDIT) ||
-       /* This is needed so linked duplicates show updates while the user edits the mesh.
-        * While this is not essential, it's useful to see the edit-mode changes everywhere. */
-       (me->edit_mesh->mesh_eval_final != NULL));
+  const bool is_editmode = (me->edit_mesh != NULL) && DRW_object_is_in_edit_mode(ob);
 
   DRWBatchFlag batch_requested = cache->batch_requested;
   cache->batch_requested = 0;
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 2fbb0a740cf..7397490d406 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -167,7 +167,8 @@ bool DRW_object_is_renderable(const Object *ob)
   BLI_assert((ob->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0);
 
   if (ob->type == OB_MESH) {
-    if ((ob == DST.draw_ctx.object_edit) || BKE_object_is_in_editmode(ob)) {
+    if ((ob == DST.draw_ctx.object_edit) || DRW_object_is_in_edit_mode(ob)) {
+
       View3D *v3d = DST.draw_ctx.v3d;
       const int mask = (V3D_OVERLAY_EDIT_OCCLUDE_WIRE | V3D_OVERLAY_EDIT_WEIGHT);
 
@@ -180,6 +181,38 @@ bool DRW_object_is_renderable(const Object *ob)
   return true;
 }
 
+/* Does `ob` needs to be rendered in edit mode.
+ *
+ * When using duplicate linked meshes, objects that are not in edit-mode will be drawn as
+ * it is in edit mode, when another object with the same mesh is in edit mode.
+ * This will not be the case when one of the objects are influenced by modifiers. */
+bool DRW_object_is_in_edit_mode(const Object *ob)
+{
+  if (BKE_object_is_in_editmode(ob)) {
+    if (ob->type == OB_MESH) {
+      if ((ob->mode & OB_MODE_EDIT) == 0) {
+        Mesh *me = (Mesh *)ob->data;
+        BMEditMesh *embm = me->edit_mesh;
+        /* Sanity check when rendering in multiple windows. */
+        if (embm && embm->mesh_eval_final == NULL) {
+          return false;
+        }
+        /* Do not draw ob with edit overlay when edit data is present and is modified. */
+        if (embm && embm->mesh_eval_cage && (embm->mesh_eval_cage != embm->mesh_eval_final)) {
+          return false;
+        }
+        /* Check if the object that we are drawing is modified. */
+        if (!DEG_is_original_id(&me->id)) {
+          return false;
+        }
+        return true;
+      }
+    }
+    return true;
+  }
+  return false;
+}
+
 /**
  * Return whether this object is visible depending if
  * we are rendering or drawing in the viewport.



More information about the Bf-blender-cvs mailing list