Fix T79965: mesh.transform() modifies referenced layers

Originally was noticed when transforming mesh created by
object.to_mesh() from an object without modifier, in which case the
result references CustomData layers used by the object itself.

The issue goes a bit deeper: mesh.transform() should never modify
referenced layers, hence it should duplicate referenced layers.

This fix changes one specific aspect of the reported behavior. The
case where vertices coordinates are modified manually will still have
affect on the source mesh (as no referenced CustomData layers are being
duplicated). Proper fix for this case is not yet clear to me.

Differential Revision: https://developer.blender.org/D8939
This commit is contained in:
Sergey Sharybin 2020-09-18 12:45:59 +02:00
parent abc90d6b03
commit 3791dbea1e
Notes: blender-bot 2023-02-14 11:01:33 +01:00
Referenced by commit d32188b85b, Mesh: Fix BKE_mesh_translate changes referenced layer
Referenced by issue #79965, Stateful behavior with ID.evaluated_get(..) and Object.to_mesh(preserve_all_data_layers=True, ..)
1 changed files with 5 additions and 2 deletions

View File

@ -1512,8 +1512,11 @@ bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3])
void BKE_mesh_transform(Mesh *me, const float mat[4][4], bool do_keys)
{
int i;
MVert *mvert = me->mvert;
float(*lnors)[3] = CustomData_get_layer(&me->ldata, CD_NORMAL);
MVert *mvert = CustomData_duplicate_referenced_layer(&me->vdata, CD_MVERT, me->totvert);
float(*lnors)[3] = CustomData_duplicate_referenced_layer(&me->ldata, CD_NORMAL, me->totloop);
/* If the referenced l;ayer has been re-allocated need to update pointers stored in the mesh. */
BKE_mesh_update_customdata_pointers(me, false);
for (i = 0; i < me->totvert; i++, mvert++) {
mul_m4_v3(mat, mvert->co);