Fix #110471: Normal Edit modifier screws up UVs (backported) #110996

Merged
Philipp Oeser merged 1 commits from JacquesLucke/blender:fix-backport-normals into blender-v3.6-release 2023-08-10 13:43:12 +02:00
6 changed files with 22 additions and 12 deletions

View File

@ -428,7 +428,7 @@ void CustomData_swap_corners(struct CustomData *data, int index, const int *corn
/**
* Swap two items of given custom data, in all available layers.
*/
void CustomData_swap(struct CustomData *data, int index_a, int index_b);
void CustomData_swap(struct CustomData *data, int index_a, int index_b, const int totelem);
/**
* Retrieve a pointer to an element of the active layer of the given \a type, chosen by the

View File

@ -581,6 +581,7 @@ void BKE_mesh_polygon_flip_ex(int poly_offset,
int *corner_verts,
int *corner_edges,
struct CustomData *ldata,
int tot_loop,
float (*lnors)[3],
struct MDisps *mdisp,
bool use_loop_mdisp_flip);
@ -600,6 +601,7 @@ void BKE_mesh_polys_flip(const int *poly_offsets,
int *corner_verts,
int *corner_edges,
struct CustomData *ldata,
int totloop,
int totpoly);
/**

View File

@ -3505,7 +3505,7 @@ void CustomData_swap_corners(CustomData *data, const int index, const int *corne
}
}
void CustomData_swap(CustomData *data, const int index_a, const int index_b)
void CustomData_swap(CustomData *data, const int index_a, const int index_b, const int totelem)
{
char buff_static[256];
@ -3514,17 +3514,17 @@ void CustomData_swap(CustomData *data, const int index_a, const int index_b)
}
for (int i = 0; i < data->totlayer; i++) {
const LayerTypeInfo *typeInfo = layerType_getInfo(eCustomDataType(data->layers[i].type));
CustomDataLayer &layer = data->layers[i];
ensure_layer_data_is_mutable(layer, totelem);
const LayerTypeInfo *typeInfo = layerType_getInfo(eCustomDataType(layer.type));
const size_t size = typeInfo->size;
const size_t offset_a = size * index_a;
const size_t offset_b = size * index_b;
void *buff = size <= sizeof(buff_static) ? buff_static : MEM_mallocN(size, __func__);
memcpy(buff, POINTER_OFFSET(data->layers[i].data, offset_a), size);
memcpy(POINTER_OFFSET(data->layers[i].data, offset_a),
POINTER_OFFSET(data->layers[i].data, offset_b),
size);
memcpy(POINTER_OFFSET(data->layers[i].data, offset_b), buff, size);
memcpy(buff, POINTER_OFFSET(layer.data, offset_a), size);
memcpy(POINTER_OFFSET(layer.data, offset_a), POINTER_OFFSET(layer.data, offset_b), size);
memcpy(POINTER_OFFSET(layer.data, offset_b), buff, size);
if (buff != buff_static) {
MEM_freeN(buff);

View File

@ -539,6 +539,7 @@ void BKE_mesh_polygon_flip_ex(const int poly_offset,
int *corner_verts,
int *corner_edges,
CustomData *ldata,
int tot_loop,
float (*lnors)[3],
MDisps *mdisp,
const bool use_loop_mdisp_flip)
@ -577,7 +578,7 @@ void BKE_mesh_polygon_flip_ex(const int poly_offset,
if (lnors) {
swap_v3_v3(lnors[loopstart], lnors[loopend]);
}
CustomData_swap(ldata, loopstart, loopend);
CustomData_swap(ldata, loopstart, loopend, tot_loop);
}
/* Even if we did not swap the other 'pivot' loop, we need to set its swapped edge. */
if (loopstart == loopend) {
@ -594,11 +595,15 @@ void BKE_mesh_polygon_flip(const int poly_offset,
{
MDisps *mdisp = (MDisps *)CustomData_get_layer_for_write(ldata, CD_MDISPS, totloop);
BKE_mesh_polygon_flip_ex(
poly_offset, poly_size, corner_verts, corner_edges, ldata, nullptr, mdisp, true);
poly_offset, poly_size, corner_verts, corner_edges, ldata, totloop, nullptr, mdisp, true);
}
void BKE_mesh_polys_flip(
const int *poly_offsets, int *corner_verts, int *corner_edges, CustomData *ldata, int totpoly)
void BKE_mesh_polys_flip(const int *poly_offsets,
int *corner_verts,
int *corner_edges,
CustomData *ldata,
int totloop,
int totpoly)
{
const blender::OffsetIndices polys(blender::Span(poly_offsets, totpoly + 1));
MDisps *mdisp = (MDisps *)CustomData_get_layer_for_write(ldata, CD_MDISPS, totpoly);
@ -608,6 +613,7 @@ void BKE_mesh_polys_flip(
corner_verts,
corner_edges,
ldata,
totloop,
nullptr,
mdisp,
true);

View File

@ -175,6 +175,7 @@ static void rna_Mesh_flip_normals(Mesh *mesh)
BKE_mesh_corner_verts_for_write(mesh),
BKE_mesh_corner_edges_for_write(mesh),
&mesh->ldata,
mesh->totloop,
mesh->totpoly);
BKE_mesh_tessface_clear(mesh);
BKE_mesh_runtime_clear_geometry(mesh);

View File

@ -209,6 +209,7 @@ static bool polygons_check_flip(blender::MutableSpan<int> corner_verts,
corner_verts.data(),
corner_edges.data(),
ldata,
corner_edges.size(),
reinterpret_cast<float(*)[3]>(nos),
mdisp,
true);