From 3867bef904d5b1fbe7ac6d0f5fc02c19033e2177 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 6 Feb 2016 19:12:22 +0100 Subject: Fix T47320: Cycles baking in edit mode uses outdated mesh. --- source/blender/editors/object/object_bake_api.c | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/object') diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 1cf8614004f..51affb3e1fc 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -612,6 +612,18 @@ static size_t initialize_internal_images(BakeImages *bake_images, ReportList *re return tot_size; } +/* create new mesh with edit mode changes and modifiers applied */ +static Mesh *bake_mesh_new_from_object(Main *bmain, Scene *scene, Object *ob) +{ + if (ob->mode & OB_MODE_EDIT) + ED_object_editmode_load(ob); + + Mesh *me = BKE_mesh_new_from_object(bmain, scene, ob, 1, 2, 0, 0); + BKE_mesh_split_faces(me); + + return me; +} + static int bake( Render *re, Main *bmain, Scene *scene, Object *ob_low, ListBase *selected_objects, ReportList *reports, const ScenePassType pass_type, const int pass_filter, const int margin, @@ -751,8 +763,7 @@ static int bake( result = MEM_callocN(sizeof(float) * depth * num_pixels, "bake return pixels"); /* get the mesh as it arrives in the renderer */ - me_low = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 0, 0); - BKE_mesh_split_faces(me_low); + me_low = bake_mesh_new_from_object(bmain, scene, ob_low); /* populate the pixel array with the face data */ if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false) @@ -767,8 +778,7 @@ static int bake( /* prepare cage mesh */ if (ob_cage) { - me_cage = BKE_mesh_new_from_object(bmain, scene, ob_cage, 1, 2, 0, 0); - BKE_mesh_split_faces(me_cage); + me_cage = bake_mesh_new_from_object(bmain, scene, ob_cage); if ((me_low->totpoly != me_cage->totpoly) || (me_low->totloop != me_cage->totloop)) { BKE_report(reports, RPT_ERROR, "Invalid cage object, the cage mesh must have the same number " @@ -800,8 +810,7 @@ static int bake( ob_low->modifiers = modifiers_tmp; /* get the cage mesh as it arrives in the renderer */ - me_cage = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 0, 0); - BKE_mesh_split_faces(me_cage); + me_cage = bake_mesh_new_from_object(bmain, scene, ob_low); RE_bake_pixels_populate(me_cage, pixel_array_low, num_pixels, &bake_images, uv_layer); } @@ -827,9 +836,8 @@ static int bake( tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED; tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP; - highpoly[i].me = BKE_mesh_new_from_object(bmain, scene, highpoly[i].ob, 1, 2, 0, 0); + highpoly[i].me = bake_mesh_new_from_object(bmain, scene, highpoly[i].ob); highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER; - BKE_mesh_split_faces(highpoly[i].me); /* lowpoly to highpoly transformation matrix */ copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->obmat); @@ -931,8 +939,7 @@ cage_cleanup: md->mode &= ~eModifierMode_Render; } - me_nores = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 0, 0); - BKE_mesh_split_faces(me_nores); + me_nores = bake_mesh_new_from_object(bmain, scene, ob_low); RE_bake_pixels_populate(me_nores, pixel_array_low, num_pixels, &bake_images, uv_layer); RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_nores, normal_swizzle, ob_low->obmat); -- cgit v1.2.3