diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-05-16 18:59:45 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-05-16 19:11:47 +0300 |
commit | 4878b29b498287ae1c3f0060bd13eb5927950e91 (patch) | |
tree | acf675dbe67d439f27ab2924ad97b33d9bed225d /source/blender/blenkernel | |
parent | 9f6670ca375552c1382ac340ad184e2e1882c2aa (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_convert.c | 9 |
1 files changed, 9 insertions, 0 deletions
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; } |