diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-05-17 19:23:06 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-05-17 19:26:00 +0300 |
commit | 848967c21d0e4e78ab70b81b18f5d8b6a20099ce (patch) | |
tree | 2c3975bce53783926e70afa98d29d6c40a47aced | |
parent | 0c4ce8e55e93c76c81f70db64dc8dee52b30a9f3 (diff) |
Fix meshes.new_from_object() not preserving materials
-rw-r--r-- | source/blender/blenkernel/intern/mesh_convert.c | 12 |
1 files changed, 12 insertions, 0 deletions
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. */ |