[Bf-blender-cvs] [1266df87c86] blender-v2.93-release: Fix unreported: instances disappear when instanced mesh is in edit mode

Jacques Lucke noreply at git.blender.org
Fri Apr 16 13:06:01 CEST 2021


Commit: 1266df87c86067d7c2d18ef71dd0e5520de1a382
Author: Jacques Lucke
Date:   Fri Apr 16 13:05:32 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rB1266df87c86067d7c2d18ef71dd0e5520de1a382

Fix unreported: instances disappear when instanced mesh is in edit mode

The issue is that for historic reasons, `geometry_set_eval` does not contain
the mesh component when the object is in edit mode.

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

M	source/blender/blenkernel/intern/geometry_set_instances.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index baeed4fc3bc..07d0e520c93 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -36,30 +36,42 @@ static void geometry_set_collect_recursive_collection(const Collection &collecti
                                                       const float4x4 &transform,
                                                       Vector<GeometryInstanceGroup> &r_sets);
 
+static void add_final_mesh_as_geometry_component(const Object &object, GeometrySet &geometry_set)
+{
+  Mesh *mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(&const_cast<Object &>(object),
+                                                                     false);
+
+  if (mesh != nullptr) {
+    BKE_mesh_wrapper_ensure_mdata(mesh);
+
+    MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
+    mesh_component.replace(mesh, GeometryOwnershipType::ReadOnly);
+    mesh_component.copy_vertex_group_names_from_object(object);
+  }
+}
+
 /**
  * \note This doesn't extract instances from the "dupli" system for non-geometry-nodes instances.
  */
 static GeometrySet object_get_geometry_set_for_read(const Object &object)
 {
-  /* Objects evaluated with a nodes modifier will have a geometry set already. */
+  if (object.type == OB_MESH && object.mode == OB_MODE_EDIT) {
+    GeometrySet geometry_set;
+    if (object.runtime.geometry_set_eval != nullptr) {
+      /* `geometry_set_eval` only contains non-mesh components, see `editbmesh_build_data`. */
+      geometry_set = *object.runtime.geometry_set_eval;
+    }
+    add_final_mesh_as_geometry_component(object, geometry_set);
+    return geometry_set;
+  }
   if (object.runtime.geometry_set_eval != nullptr) {
     return *object.runtime.geometry_set_eval;
   }
 
   /* Otherwise, construct a new geometry set with the component based on the object type. */
-  GeometrySet new_geometry_set;
-
+  GeometrySet geometry_set;
   if (object.type == OB_MESH) {
-    Mesh *mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(
-        &const_cast<Object &>(object), false);
-
-    if (mesh != nullptr) {
-      BKE_mesh_wrapper_ensure_mdata(mesh);
-
-      MeshComponent &mesh_component = new_geometry_set.get_component_for_write<MeshComponent>();
-      mesh_component.replace(mesh, GeometryOwnershipType::ReadOnly);
-      mesh_component.copy_vertex_group_names_from_object(object);
-    }
+    add_final_mesh_as_geometry_component(object, geometry_set);
   }
 
   /* TODO: Cover the case of point-clouds without modifiers-- they may not be covered by the
@@ -68,7 +80,7 @@ static GeometrySet object_get_geometry_set_for_read(const Object &object)
   /* TODO: Add volume support. */
 
   /* Return by value since there is not always an existing geometry set owned elsewhere to use. */
-  return new_geometry_set;
+  return geometry_set;
 }
 
 static void geometry_set_collect_recursive_collection_instance(



More information about the Bf-blender-cvs mailing list