Save 'deform_only' flag in Mesh.runtime
authorSybren A. Stüvel <sybren@stuvel.eu>
Tue, 15 May 2018 11:26:24 +0000 (13:26 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Wed, 16 May 2018 10:41:48 +0000 (12:41 +0200)
This flag is copied when converting between DM and Mesh.

This flag is set to true in get_mesh(), to mimick the behaviour of
CDDM_from_mesh_ex. This is necessary for the particle system to work
correctly.

source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/mesh.c
source/blender/makesdna/DNA_mesh_types.h
source/blender/modifiers/intern/MOD_util.c

index c58d946cc990cdcac81c39b2f5971397ce8b80ff..beef57a6867156e9ed1f8a8934d7980bc94b81cd 100644 (file)
@@ -749,6 +749,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob, CustomDataMask mask, bool
        CustomData_copy(&dm->loopData, &tmp.ldata, mask, alloctype, totloop);
        CustomData_copy(&dm->polyData, &tmp.pdata, mask, alloctype, totpoly);
        tmp.cd_flag = dm->cd_flag;
+       tmp.runtime.deformed_only = dm->deformedOnly;
 
        if (CustomData_has_layer(&dm->vertData, CD_SHAPEKEY)) {
                KeyBlock *kb;
@@ -2397,7 +2398,7 @@ static void mesh_calc_modifiers(
                                append_mask |= CD_MASK_PREVIEW_MLOOPCOL;
                        }
 
-                       // dm->deformedOnly = false; // XXX: Does Mesh need this? Looks to be used only by particle system
+                       mesh->runtime.deformed_only = false;
                }
 
                isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform);
index 46dd376e06529b5d8ee2c1e36466e20e916f25f4..e585c4ca666b3a6ed42a094e98ec0bc3698079e4 100644 (file)
@@ -608,7 +608,7 @@ DerivedMesh *CDDM_from_mesh_ex(Mesh *mesh, int alloctype)
        DM_init(dm, DM_TYPE_CDDM, mesh->totvert, mesh->totedge, 0 /* mesh->totface */,
                mesh->totloop, mesh->totpoly);
 
-       dm->deformedOnly = 1;
+       dm->deformedOnly = mesh->runtime.deformed_only;
        dm->cd_flag = mesh->cd_flag;
 
        if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) {
index a64eb5aa071c847cc215ad0fc817da59e526ae2c..efafdf949dc2cb0a64088d2302ec21c9ee6d8223 100644 (file)
@@ -553,6 +553,7 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int
        me_dst->edit_btmesh = NULL;
        me_dst->runtime.batch_cache = NULL;
        me_dst->runtime.bvh_cache = NULL;
+       me_dst->runtime.deformed_only = me_src->runtime.deformed_only;
 
        me_dst->mselect = MEM_dupallocN(me_dst->mselect);
        me_dst->bb = MEM_dupallocN(me_dst->bb);
index 5ce24916c54cc8e085bb0ce3dc1a7d3dbfb46b2b..4e347cc4363d2bc98e5f1e51664e3267ef106e6b 100644 (file)
@@ -93,6 +93,9 @@ typedef struct MeshRuntime {
 
        /** 'BVHCache', for 'BKE_bvhutil.c' */
        struct LinkNode *bvh_cache;
+
+       int deformed_only; /* set by modifier stack if only deformed from original */
+       char padding[4];
 } MeshRuntime;
 
 typedef struct Mesh {
index f3da8d054ecf9a14ffe9bf1aa800dad6355d9115..c5593cd004ef52c76342a1df0795f77cbf4da90f 100644 (file)
@@ -313,6 +313,7 @@ Mesh *get_mesh(
                                LIB_ID_CREATE_NO_DEG_TAG |
                                LIB_ID_COPY_NO_PREVIEW,
                                false);
+                       mesh->runtime.deformed_only = 1;
                }
 
                /* TODO(sybren): after modifier conversion of DM to Mesh is done, check whether