[Bf-blender-cvs] [848967c21d0] master: Fix meshes.new_from_object() not preserving materials

Sergey Sharybin noreply at git.blender.org
Fri May 17 18:27:44 CEST 2019


Commit: 848967c21d0e4e78ab70b81b18f5d8b6a20099ce
Author: Sergey Sharybin
Date:   Fri May 17 18:23:06 2019 +0200
Branches: master
https://developer.blender.org/rB848967c21d0e4e78ab70b81b18f5d8b6a20099ce

Fix meshes.new_from_object() not preserving materials

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

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 2ac7d4b02a9..dca5248c0fa 100644
--- a/source/blender/blenkernel/intern/mesh_convert.c
+++ b/source/blender/blenkernel/intern/mesh_convert.c
@@ -1165,6 +1165,18 @@ Mesh *BKE_mesh_new_from_object_to_bmain(Main *bmain, Object *object)
    * to the bmain. So we allocate new empty mesh in the bmain (which guarantess all the naming and
    * orders and flags) and move the temporary mesh in place there. */
   Mesh *mesh_in_bmain = BKE_mesh_add(bmain, mesh->id.name + 2);
+
+  /* NOTE: BKE_mesh_nomain_to_mesh() does not copy materials and instead it preserves them in the
+   * destinaion mesh .So we "steal" all related fields before calling it.
+   *
+   * TODO(sergey): We really better have a function which gets and ID and accepts it for the bmain.
+   */
+  mesh_in_bmain->mat = mesh->mat;
+  mesh_in_bmain->totcol = mesh->totcol;
+  mesh_in_bmain->flag = mesh->flag;
+  mesh_in_bmain->smoothresh = mesh->smoothresh;
+  mesh->mat = NULL;
+
   BKE_mesh_nomain_to_mesh(mesh, mesh_in_bmain, NULL, &CD_MASK_MESH, true);
 
   /* Make sure user count from BKE_mesh_add() is the one we expect here and bring it down to 0. */



More information about the Bf-blender-cvs mailing list