diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-01-15 15:03:09 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-01-18 20:39:43 +0300 |
commit | c9938ebb0064675a17c92e8112fc4d416bba5f7c (patch) | |
tree | eb10e9f728cab5aef0771c0635cf1aae1cf15630 /source/blender/editors | |
parent | 985dcbf6db1199dc247a2c6bb13c380035a613e6 (diff) |
Fix T60615: Cycles baking not working with some modifiers.
Refactors Cycles mesh export a bit to avoid unnecessary copies and to be in
sync with the Blender baker.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/object/object_bake_api.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 81715890f0a..5f403dad54a 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -635,15 +635,9 @@ static size_t initialize_internal_images(BakeImages *bake_images, ReportList *re /* create new mesh with edit mode changes and modifiers applied */ static Mesh *bake_mesh_new_from_object(Depsgraph *depsgraph, Main *bmain, Scene *scene, Object *ob) { - bool apply_modifiers = false; + bool apply_modifiers = (ob->type != OB_MESH); + Mesh *me = BKE_mesh_new_from_object(depsgraph, bmain, scene, ob, apply_modifiers, false); - /* Mesh is already updated and has modifiers applied. */ - if (ob->type != OB_MESH) { - ED_object_editmode_load(bmain, ob); - apply_modifiers = true; - } - - Mesh *me = BKE_mesh_new_from_object(depsgraph, bmain, scene, ob, apply_modifiers, 0); if (me->flag & ME_AUTOSMOOTH) { BKE_mesh_split_faces(me, true); } @@ -812,7 +806,7 @@ static int bake( ob_low_eval = DEG_get_evaluated_object(depsgraph, ob_low); /* get the mesh as it arrives in the renderer */ - me_low = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low); + me_low = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low_eval); /* populate the pixel array with the face data */ if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false) @@ -825,7 +819,7 @@ static int bake( /* prepare cage mesh */ if (ob_cage) { - me_cage = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_cage); + me_cage = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_cage_eval); 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 " @@ -834,6 +828,8 @@ static int bake( } } else if (is_cage) { + BKE_object_eval_reset(ob_low_eval); + ModifierData *md = ob_low_eval->modifiers.first; while (md) { ModifierData *md_next = md->next; @@ -851,7 +847,6 @@ static int bake( md = md_next; } - BKE_object_eval_reset(ob_low_eval); me_cage = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low_eval); RE_bake_pixels_populate(me_cage, pixel_array_low, num_pixels, &bake_images, uv_layer); } @@ -867,10 +862,10 @@ static int bake( /* initialize highpoly_data */ highpoly[i].ob = ob_iter; - highpoly[i].me = bake_mesh_new_from_object(depsgraph, bmain, scene, highpoly[i].ob); highpoly[i].ob_eval = DEG_get_evaluated_object(depsgraph, ob_iter); highpoly[i].ob_eval->restrictflag &= ~OB_RESTRICT_RENDER; highpoly[i].ob_eval->base_flag |= (BASE_VISIBLE | BASE_ENABLED_RENDER); + highpoly[i].me = bake_mesh_new_from_object(depsgraph, bmain, scene, highpoly[i].ob_eval); /* lowpoly to highpoly transformation matrix */ copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->obmat); @@ -894,7 +889,7 @@ static int bake( /* populate the pixel arrays with the corresponding face data for each high poly object */ if (!RE_bake_pixels_populate_from_objects( me_low, pixel_array_low, pixel_array_high, highpoly, tot_highpoly, num_pixels, ob_cage != NULL, - cage_extrusion, ob_low->obmat, (ob_cage ? ob_cage->obmat : ob_low->obmat), me_cage)) + cage_extrusion, ob_low_eval->obmat, (ob_cage ? ob_cage->obmat : ob_low_eval->obmat), me_cage)) { BKE_report(reports, RPT_ERROR, "Error handling selected objects"); goto cleanup; @@ -912,10 +907,10 @@ static int bake( } else { /* If low poly is not renderable it should have failed long ago. */ - BLI_assert((ob_low->restrictflag & OB_RESTRICT_RENDER) == 0); + BLI_assert((ob_low_eval->restrictflag & OB_RESTRICT_RENDER) == 0); if (RE_bake_has_engine(re)) { - ok = RE_bake_engine(re, depsgraph, ob_low, 0, pixel_array_low, num_pixels, depth, pass_type, pass_filter, result); + ok = RE_bake_engine(re, depsgraph, ob_low_eval, 0, pixel_array_low, num_pixels, depth, pass_type, pass_filter, result); } else { BKE_report(reports, RPT_ERROR, "Current render engine does not support baking"); @@ -943,13 +938,13 @@ static int bake( } case R_BAKE_SPACE_OBJECT: { - RE_bake_normal_world_to_object(pixel_array_low, num_pixels, depth, result, ob_low, normal_swizzle); + RE_bake_normal_world_to_object(pixel_array_low, num_pixels, depth, result, ob_low_eval, normal_swizzle); break; } case R_BAKE_SPACE_TANGENT: { if (is_selected_to_active) { - RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_low, normal_swizzle, ob_low->obmat); + RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_low, normal_swizzle, ob_low_eval->obmat); } else { /* from multiresolution */ @@ -957,17 +952,19 @@ static int bake( ModifierData *md = NULL; int mode; - md = modifiers_findByType(ob_low, eModifierType_Multires); + BKE_object_eval_reset(ob_low_eval); + md = modifiers_findByType(ob_low_eval, eModifierType_Multires); if (md) { mode = md->mode; md->mode &= ~eModifierMode_Render; } - me_nores = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low); + /* Evaluate modifiers again. */ + me_nores = BKE_mesh_new_from_object(depsgraph, bmain, scene, ob_low_eval, true, false); 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); + RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_nores, normal_swizzle, ob_low_eval->obmat); BKE_id_free(bmain, me_nores); if (md) @@ -1029,8 +1026,8 @@ static int bake( BLI_path_suffix(name, FILE_MAX, bk_image->image->id.name + 2, "_"); } else { - if (ob_low->mat[i]) { - BLI_path_suffix(name, FILE_MAX, ob_low->mat[i]->id.name + 2, "_"); + if (ob_low_eval->mat[i]) { + BLI_path_suffix(name, FILE_MAX, ob_low_eval->mat[i]->id.name + 2, "_"); } else if (me_low->mat[i]) { BLI_path_suffix(name, FILE_MAX, me_low->mat[i]->id.name + 2, "_"); |