Fix T95250: bake margin adjacent faces uses stale UV map in edit mode

Use the evaluated mesh to generate the Adjacent Faces margin.

Baking used the evaluated mesh, but generating the margin used the base
mesh. This would lead to generating the margin from a stale UV map when the
UV editor was open and the UV map was changed. Fix it by passing the same
mesh as used for baking through to the margin generation.

Differential Revision: https://developer.blender.org/D13938
This commit is contained in:
Martijn Versteegh 2022-01-31 13:56:51 +01:00 committed by Brecht Van Lommel
parent 83fa6a1b2a
commit 8ad5241778
Notes: blender-bot 2023-02-13 16:24:18 +01:00
Referenced by issue #95250, Texture border generation. Adjacent faces  uses stale UV map when in edit mode.
1 changed files with 12 additions and 12 deletions

View File

@ -188,7 +188,7 @@ static bool write_internal_bake_pixels(Image *image,
const char margin_type,
const bool is_clear,
const bool is_noncolor,
Mesh const *mesh,
Mesh const *mesh_eval,
char const *uv_layer)
{
ImBuf *ibuf;
@ -285,7 +285,7 @@ static bool write_internal_bake_pixels(Image *image,
/* margins */
if (margin > 0) {
RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh, uv_layer);
RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh_eval, uv_layer);
}
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
@ -334,7 +334,7 @@ static bool write_external_bake_pixels(const char *filepath,
const int margin_type,
ImageFormatData *im_format,
const bool is_noncolor,
Mesh const *mesh,
Mesh const *mesh_eval,
char const *uv_layer)
{
ImBuf *ibuf = NULL;
@ -392,7 +392,7 @@ static bool write_external_bake_pixels(const char *filepath,
mask_buffer = MEM_callocN(sizeof(char) * num_pixels, "Bake Mask");
RE_bake_mask_fill(pixel_array, num_pixels, mask_buffer);
RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh, uv_layer);
RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh_eval, uv_layer);
if (mask_buffer) {
MEM_freeN(mask_buffer);
@ -774,10 +774,10 @@ static bool bake_targets_output_internal(const BakeAPIRender *bkr,
BakeTargets *targets,
Object *ob,
BakePixel *pixel_array,
ReportList *reports)
ReportList *reports,
Mesh *mesh_eval)
{
bool all_ok = true;
const Mesh *me = (Mesh *)ob->data;
for (int i = 0; i < targets->num_images; i++) {
BakeImage *bk_image = &targets->images[i];
@ -791,7 +791,7 @@ static bool bake_targets_output_internal(const BakeAPIRender *bkr,
bkr->margin_type,
bkr->is_clear,
targets->is_noncolor,
me,
mesh_eval,
bkr->uv_layer);
/* might be read by UI to set active image for display */
@ -852,7 +852,7 @@ static bool bake_targets_output_external(const BakeAPIRender *bkr,
BakeTargets *targets,
Object *ob,
Object *ob_eval,
Mesh *me,
Mesh *mesh_eval,
BakePixel *pixel_array,
ReportList *reports)
{
@ -886,8 +886,8 @@ static bool bake_targets_output_external(const BakeAPIRender *bkr,
if (ob_eval->mat[i]) {
BLI_path_suffix(name, FILE_MAX, ob_eval->mat[i]->id.name + 2, "_");
}
else if (me->mat[i]) {
BLI_path_suffix(name, FILE_MAX, me->mat[i]->id.name + 2, "_");
else if (mesh_eval->mat[i]) {
BLI_path_suffix(name, FILE_MAX, mesh_eval->mat[i]->id.name + 2, "_");
}
else {
/* if everything else fails, use the material index */
@ -909,7 +909,7 @@ static bool bake_targets_output_external(const BakeAPIRender *bkr,
bkr->margin_type,
&bake->im_format,
targets->is_noncolor,
me,
mesh_eval,
bkr->uv_layer);
if (!ok) {
@ -1211,7 +1211,7 @@ static bool bake_targets_output(const BakeAPIRender *bkr,
{
if (bkr->target == R_BAKE_TARGET_IMAGE_TEXTURES) {
if (bkr->save_mode == R_BAKE_SAVE_INTERNAL) {
return bake_targets_output_internal(bkr, targets, ob, pixel_array, reports);
return bake_targets_output_internal(bkr, targets, ob, pixel_array, reports, me_eval);
}
if (bkr->save_mode == R_BAKE_SAVE_EXTERNAL) {
return bake_targets_output_external(