From 16b04834b3e1046118787d40531bf38f73ec9c76 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 21 Oct 2010 01:08:12 +0000 Subject: improved fix for [#24267] Hook fails after Solidify Rather then have the modifier calculate ORIGINDEX weather its needed or not (incorrect if it wasn't the first modifier on the stack), create ORIGINDEX layer initially if any of the modifiers use it. This way hook also works after Mirror and Screw modifiers which have the ORIGINDEX layer copied implicitly with DM_copy_vert_data(). This wasn't possible to check for before because this flag was always enabled so it would be passed to DM_set_only_copy(). Now just add the flag whenever calling DM_set_only_copy(). --- source/blender/blenkernel/intern/DerivedMesh.c | 41 ++++++++++++++------------ source/blender/modifiers/intern/MOD_hook.c | 5 ++-- source/blender/modifiers/intern/MOD_solidify.c | 17 ----------- 3 files changed, 24 insertions(+), 39 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index c213a5a4ce2..3d87b77dec9 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1693,9 +1693,6 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos if(useRenderParams) required_mode = eModifierMode_Render; else required_mode = eModifierMode_Realtime; - /* we always want to keep original indices */ - dataMask |= CD_MASK_ORIGINDEX; - datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode); curr = datamasks; @@ -1816,6 +1813,12 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } else { DerivedMesh *ndm; + /* determine which data layers are needed by following modifiers */ + if(curr->next) + nextmask= (CustomDataMask)GET_INT_FROM_POINTER(curr->next->link); + else + nextmask= dataMask; + /* apply vertex coordinates or build a DerivedMesh as necessary */ if(dm) { if(deformedVerts) { @@ -1837,9 +1840,15 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT)) add_weight_mcol_dm(ob, dm); - /* constructive modifiers need to have an origindex - * otherwise they wont have anywhere to copy the data from */ - if(needMapping) { + /* Constructive modifiers need to have an origindex + * otherwise they wont have anywhere to copy the data from. + * + * Also create ORIGINDEX data if any of the following modifiers + * requests it, this way Mirror, Solidify etc will keep ORIGINDEX + * data by using generic DM_copy_vert_data() functions. + */ + if(needMapping || (nextmask & CD_MASK_ORIGINDEX)) { + /* calc */ DM_add_vert_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL); DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL); DM_add_face_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL); @@ -1850,11 +1859,6 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } } - /* determine which data layers are needed by following modifiers */ - if(curr->next) - nextmask= (CustomDataMask)GET_INT_FROM_POINTER(curr->next->link); - else - nextmask= dataMask; /* set the DerivedMesh to only copy needed data */ mask= (CustomDataMask)GET_INT_FROM_POINTER(curr->link); @@ -1891,7 +1895,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos orcodm= create_orco_dm(ob, me, NULL, CD_ORCO); nextmask &= ~CD_MASK_ORCO; - DM_set_only_copy(orcodm, nextmask); + DM_set_only_copy(orcodm, nextmask | CD_MASK_ORIGINDEX); ndm = mti->applyModifier(md, ob, orcodm, useRenderParams, 0); if(ndm) { @@ -1907,7 +1911,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos clothorcodm= create_orco_dm(ob, me, NULL, CD_CLOTH_ORCO); nextmask &= ~CD_MASK_CLOTH_ORCO; - DM_set_only_copy(clothorcodm, nextmask); + DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX); ndm = mti->applyModifier(md, ob, clothorcodm, useRenderParams, 0); if(ndm) { @@ -2025,9 +2029,6 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri dm = NULL; md = modifiers_getVirtualModifierList(ob); - - /* we always want to keep original indices */ - dataMask |= CD_MASK_ORIGINDEX; datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode); @@ -2106,7 +2107,7 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri orcodm= create_orco_dm(ob, ob->data, em, CD_ORCO); mask &= ~CD_MASK_ORCO; - DM_set_only_copy(orcodm, mask); + DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX); if (mti->applyModifierEM) ndm = mti->applyModifierEM(md, ob, em, orcodm); @@ -2121,9 +2122,11 @@ static void editmesh_calc_modifiers(Scene *scene, Object *ob, EditMesh *em, Deri } /* set the DerivedMesh to only copy needed data */ - DM_set_only_copy(dm, (CustomDataMask)GET_INT_FROM_POINTER(curr->link)); + mask= (CustomDataMask)GET_INT_FROM_POINTER(curr->link); /* CD_MASK_ORCO may have been cleared above */ - if(((CustomDataMask)GET_INT_FROM_POINTER(curr->link)) & CD_MASK_ORIGSPACE) + DM_set_only_copy(dm, mask | CD_MASK_ORIGINDEX); + + if(mask & CD_MASK_ORIGSPACE) if(!CustomData_has_layer(&dm->faceData, CD_ORIGSPACE)) DM_add_face_layer(dm, CD_ORIGSPACE, CD_DEFAULT, NULL); diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index c26d3ff0967..b7d853d757a 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -76,7 +76,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) /* ask for vertexgroups if we need them */ if(hmd->name[0]) dataMask |= (1 << CD_MDEFORMVERT); - // if(hmd->indexar) dataMask |= CD_MASK_ORIGINDEX; + if(hmd->indexar) dataMask |= CD_MASK_ORIGINDEX; return dataMask; } @@ -138,7 +138,7 @@ static float hook_falloff(float *co_1, float *co_2, const float falloff_squared, } static void deformVerts(ModifierData *md, Object *ob, - DerivedMesh *derivedData, + DerivedMesh *dm, float (*vertexCos)[3], int numVerts, int UNUSED(useRenderParams), @@ -148,7 +148,6 @@ static void deformVerts(ModifierData *md, Object *ob, bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget); float vec[3], mat[4][4], dmat[4][4]; int i, *index_pt; - DerivedMesh *dm = derivedData; const float falloff_squared= hmd->falloff * hmd->falloff; /* for faster comparisons */ int max_dvert= 0; diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c index b54f8fdf190..416dc94d9d2 100644 --- a/source/blender/modifiers/intern/MOD_solidify.c +++ b/source/blender/modifiers/intern/MOD_solidify.c @@ -336,23 +336,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DM_copy_vert_data(dm, result, 0, 0, numVerts); DM_copy_vert_data(dm, result, 0, numVerts, numVerts); - /* CDDM_from_template() gives zero'd ORIGINDEX data, we can know ahead of time what the - * indicies will be however it would be better if we could check if the're needed. */ - index= DM_get_vert_data_layer(result, CD_ORIGINDEX); - range_vni(index, numVerts, 0); - memcpy(index+numVerts, index, numVerts * sizeof(int)); - - index= DM_get_edge_data_layer(result, CD_ORIGINDEX); - range_vni(index, numEdges, 0); - memcpy(index+numEdges, index, numEdges * sizeof(int)); - fill_vni(index+numEdges*2, newEdges, ORIGINDEX_NONE); - - index= DM_get_face_data_layer(result, CD_ORIGINDEX); - range_vni(index, numFaces, 0); - memcpy(index+numFaces, index, numFaces * sizeof(int)); - fill_vni(index+numFaces*2, newFaces, ORIGINDEX_NONE); - /* done setting origindex values */ - { static int corner_indices[4] = {2, 1, 0, 3}; int is_quad; -- cgit v1.2.3