[Bf-blender-cvs] [4878b29b498] master: Use edit evaluated mesh when creating mesh for object in edit mode

Sergey Sharybin noreply at git.blender.org
Thu May 16 18:13:29 CEST 2019


Commit: 4878b29b498287ae1c3f0060bd13eb5927950e91
Author: Sergey Sharybin
Date:   Thu May 16 17:59:45 2019 +0200
Branches: master
https://developer.blender.org/rB4878b29b498287ae1c3f0060bd13eb5927950e91

Use edit evaluated mesh when creating mesh for object in edit mode

Makes the result of object.to_mesh() and bpy.meshes.new_from_object()
to be the same as what is visible in the viewport.

This makes Cycles to respect modifiers enabled in edit mode, and should
also easy some scripter's work. The final render still needs some work,
which, maybe, will be about forcing objects out of editing modes.

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

M	source/blender/blenkernel/intern/mesh_convert.c

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

diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c
index 6d0245cbc88..2ac7d4b02a9 100644
--- a/source/blender/blenkernel/intern/mesh_convert.c
+++ b/source/blender/blenkernel/intern/mesh_convert.c
@@ -34,9 +34,11 @@
 #include "BLI_math.h"
 #include "BLI_listbase.h"
 #include "BLI_edgehash.h"
+#include "BLI_string.h"
 
 #include "BKE_main.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_editmesh.h"
 #include "BKE_key.h"
 #include "BKE_library_query.h"
 #include "BKE_mesh.h"
@@ -1084,12 +1086,19 @@ static Mesh *mesh_new_from_mball_object(Object *object)
 static Mesh *mesh_new_from_mesh_object(Object *object)
 {
   Mesh *mesh_input = object->data;
+  /* If we are in edit mode, use evaluated mesh from edit structure, matching to what
+   * viewport is using for visualization. */
+  if (mesh_input->edit_mesh != NULL && mesh_input->edit_mesh->mesh_eval_final) {
+    mesh_input = mesh_input->edit_mesh->mesh_eval_final;
+  }
   Mesh *mesh_result = NULL;
   BKE_id_copy_ex(NULL,
                  &mesh_input->id,
                  (ID **)&mesh_result,
                  LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT);
   /* NOTE: Materials should already be copied. */
+  /* Copy original mesh name. This is because edit meshes might not have one properly set name. */
+  BLI_strncpy(mesh_result->id.name, ((ID *)object->data)->name, sizeof(mesh_result->id.name));
   return mesh_result;
 }



More information about the Bf-blender-cvs mailing list