Todo issue: sculpting on deformed mesh
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 31 Jan 2011 20:02:51 +0000 (20:02 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 31 Jan 2011 20:02:51 +0000 (20:02 +0000)
Used a crazyspace approach (like in edit mode), but only modifiers with
deformMatricies are allowed atm (currently shapekeys and armature modifiers only).
All the rest modifiers had an warning message that they aren't applied because
of sculpt mode. Deformation of multires is also unsupported.

With all this restictions users will always see the actual "layer" (or maybe
mesh state would be more correct word) they are sculpting on.

Internal changes:
- All modifiers could have deformMatricies callback (the same as deformMatriciesEM but
  for non-edit mode usage)
- Added function to build crazyspace for sculpting (sculpt_get_deform_matrices), but it
  could be generalized for usage in other painting modes (particle edit mode, i.e)

Todo:
- Implement crazyspace correction to support all kinds of deformation modifiers
- Maybe deformation of multires isn't so difficult?
- And maybe we could avoid extra bad-level-stub for ED_sculpt_modifiers_changed
  without code duplicating?

53 files changed:
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_modifier.h
source/blender/blenkernel/BKE_multires.h
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/BLI_pbvh.h
source/blender/blenlib/intern/math_matrix.c
source/blender/blenlib/intern/pbvh.c
source/blender/editors/include/ED_sculpt.h
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_intern.h
source/blender/editors/sculpt_paint/sculpt_undo.c
source/blender/modifiers/intern/MOD_armature.c
source/blender/modifiers/intern/MOD_array.c
source/blender/modifiers/intern/MOD_bevel.c
source/blender/modifiers/intern/MOD_boolean.c
source/blender/modifiers/intern/MOD_build.c
source/blender/modifiers/intern/MOD_cast.c
source/blender/modifiers/intern/MOD_cloth.c
source/blender/modifiers/intern/MOD_collision.c
source/blender/modifiers/intern/MOD_curve.c
source/blender/modifiers/intern/MOD_decimate.c
source/blender/modifiers/intern/MOD_displace.c
source/blender/modifiers/intern/MOD_edgesplit.c
source/blender/modifiers/intern/MOD_explode.c
source/blender/modifiers/intern/MOD_fluidsim.c
source/blender/modifiers/intern/MOD_hook.c
source/blender/modifiers/intern/MOD_lattice.c
source/blender/modifiers/intern/MOD_mask.c
source/blender/modifiers/intern/MOD_meshdeform.c
source/blender/modifiers/intern/MOD_mirror.c
source/blender/modifiers/intern/MOD_multires.c
source/blender/modifiers/intern/MOD_none.c
source/blender/modifiers/intern/MOD_particleinstance.c
source/blender/modifiers/intern/MOD_particlesystem.c
source/blender/modifiers/intern/MOD_screw.c
source/blender/modifiers/intern/MOD_shapekey.c
source/blender/modifiers/intern/MOD_shrinkwrap.c
source/blender/modifiers/intern/MOD_simpledeform.c
source/blender/modifiers/intern/MOD_smoke.c
source/blender/modifiers/intern/MOD_smooth.c
source/blender/modifiers/intern/MOD_softbody.c
source/blender/modifiers/intern/MOD_solidify.c
source/blender/modifiers/intern/MOD_subsurf.c
source/blender/modifiers/intern/MOD_surface.c
source/blender/modifiers/intern/MOD_uvproject.c
source/blender/modifiers/intern/MOD_wave.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index 5ce6c522e9011c2cdfd858275c6739ce815e7aa0..48127d3cf4c4a978c349399882da69d79c1a00be 100644 (file)
@@ -508,6 +508,10 @@ void makeDerivedMesh(struct Scene *scene, struct Object *ob, struct EditMesh *em
 int editmesh_get_first_deform_matrices(struct Scene *, struct Object *, struct EditMesh *em,
                                                                           float (**deformmats)[3][3], float (**deformcos)[3]);
 
+/* returns an array of deform matrices for crazyspace correction when sculpting */
+void sculpt_get_deform_matrices(struct Scene *scene, struct Object *ob,
+                                                               float (**deformmats)[3][3], float (**deformcos)[3]);
+
 void weight_to_rgb(float input, float *fr, float *fg, float *fb);
 
 /* convert layers requested by a GLSL material to actually available layers in
index 97bef6ab5657b5c6e314c54981f2c6ab1fa21bdb..5bef7527c87d5f4fb84f752d913376d5b94f7763 100644 (file)
@@ -134,6 +134,12 @@ typedef struct ModifierTypeInfo {
                                                float (*vertexCos)[3], int numVerts,
                                                int useRenderParams, int isFinalCalc);
 
+       /* Like deformMatricesEM but called from object mode (for supporting modifiers in sculpt mode) */
+       void (*deformMatrices)(
+                               struct ModifierData *md, struct Object *ob,
+                               struct DerivedMesh *derivedData,
+                               float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+
        /* Like deformVerts but called during editmode (for supporting modifiers)
         */
        void (*deformVertsEM)(
index 5cafd24c1fd50347353cb20770b8e55973e7a785..23fabce68bab732a1a7c78cdc5c66f8736f4bc7b 100644 (file)
@@ -53,6 +53,7 @@ struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*
 
 struct MultiresModifierData *find_multires_modifier_before(struct Scene *scene,
        struct ModifierData *lastmd);
+struct MultiresModifierData *get_multires_modifier(struct Scene *scene, struct Object *ob, int use_first);
 struct DerivedMesh *get_multires_dm(struct Scene *scene, struct MultiresModifierData *mmd,
                                struct Object *ob);
 void multiresModifier_del_levels(struct MultiresModifierData *, struct Object *, int direction);
index 20742033a2e9945bc69920f96575d0ad6e37ed47..2203277b30167be7a691ec3ed2a5a166f88ec2c6 100644 (file)
@@ -78,8 +78,11 @@ typedef struct SculptSession {
        /* PBVH acceleration structure */
        struct PBVH *pbvh;
 
-       /* Used temporarily per-stroke */
-       float *vertexcosnos;
+       /* Paiting on deformed mesh */
+       int modifiers_active; /* object is deformed with some modifiers */
+       float (*orig_cos)[3]; /* coords of undeformed mesh */
+       float (*deform_cos)[3]; /* coords of deformed mesh but without stroke displacement */
+       float (*deform_imats)[3][3]; /* crazyspace deformation matricies */
 
        /* Partial redraw */
        int partial_redraw;
@@ -95,8 +98,6 @@ typedef struct SculptSession {
 
        struct GPUDrawObject *drawobject;
 
-       int modifiers_active;
-
        rcti previous_r;
 } SculptSession;
 
index 940a0027d0b01a622a1b85a1ce67e1bd6bdd2ce4..ef3ad3ad2e90358673f549ad05d6107af3e3360d 100644 (file)
@@ -72,7 +72,6 @@ typedef struct CCGDerivedMesh {
        char *faceFlags;
 
        struct PBVH *pbvh;
-       int pbvh_draw;
        struct ListBase *fmap;
        struct IndexNode *fmap_mem;
 
index a2ef625c6e6de6122bfac9d6dbee8ddcd63101eb..658d29f00460807746ae45862fdd3e1ee7baa122 100644 (file)
@@ -53,6 +53,7 @@
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_texture.h"
+#include "BKE_multires.h"
 
 
 #include "BLO_sys_types.h" // for intptr_t support
@@ -65,6 +66,8 @@
 #include "GPU_extensions.h"
 #include "GPU_material.h"
 
+#include "ED_sculpt.h" /* for ED_sculpt_modifiers_changed */
+
 ///////////////////////////////////
 ///////////////////////////////////
 
@@ -1676,6 +1679,12 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
        int required_mode;
        int isPrevDeform= FALSE;
        int skipVirtualArmature = (useDeform < 0);
+       MultiresModifierData *mmd= get_multires_modifier(scene, ob, 0);
+       int has_multires = mmd != NULL, multires_applied = 0;
+       int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt;
+
+       if(mmd && !mmd->sculptlvl)
+               has_multires = 0;
 
        if(!skipVirtualArmature) {
                firstmd = modifiers_getVirtualModifierList(ob);
@@ -1714,6 +1723,12 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                        if(useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue;
 
                        if(mti->type == eModifierTypeType_OnlyDeform) {
+                               if(sculpt_mode && !has_multires)
+                                       if(!ELEM(md->type, eModifierType_Armature, eModifierType_ShapeKey)) {
+                                               modifier_setError(md, "Not supported in sculpt mode.");
+                                               continue;
+                                       }
+
                                if(!deformedVerts)
                                        deformedVerts = mesh_getVertexCos(me, &numVerts);
 
@@ -1759,13 +1774,18 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
                md->scene= scene;
-               
+
                if(!modifier_isEnabled(scene, md, required_mode)) continue;
                if(mti->type == eModifierTypeType_OnlyDeform && !useDeform) continue;
                if((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
                        modifier_setError(md, "Modifier requires original data, bad stack position.");
                        continue;
                }
+               if(sculpt_mode && (!has_multires || multires_applied))
+                       if(md->type != eModifierType_Armature || multires_applied) {
+                               modifier_setError(md, "Not supported in sculpt mode.");
+                               continue;
+                       }
                if(needMapping && !modifier_supportsMapping(md)) continue;
                if(useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue;
 
@@ -1928,6 +1948,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
                /* grab modifiers until index i */
                if((index >= 0) && (modifiers_indexInObject(ob, md) >= index))
                        break;
+
+               if(sculpt_mode && md->type == eModifierType_Multires)
+                       multires_applied = 1;
        }
 
        for(md=firstmd; md; md=md->next)
@@ -2222,14 +2245,9 @@ static void clear_mesh_caches(Object *ob)
                ob->derivedDeform->release(ob->derivedDeform);
                ob->derivedDeform= NULL;
        }
-       /* we free pbvh on changes, except during sculpt since it can't deal with
-          changing PVBH node organization, we hope topology does not change in
-          the meantime .. weak */
-       if(ob->sculpt && ob->sculpt->pbvh) {
-               if(!ob->sculpt->cache) {
-                       BLI_pbvh_free(ob->sculpt->pbvh);
-                       ob->sculpt->pbvh= NULL;
-               }
+
+       if(ob->sculpt) {
+               ED_sculpt_modifiers_changed(ob);
        }
 }
 
@@ -2523,6 +2541,51 @@ int editmesh_get_first_deform_matrices(Scene *scene, Object *ob, EditMesh *em, f
        return numleft;
 }
 
+void sculpt_get_deform_matrices(Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3])
+{
+       ModifierData *md;
+       DerivedMesh *dm;
+       int a, numVerts= 0;
+       float (*defmats)[3][3]= NULL, (*deformedVerts)[3]= NULL;
+       MultiresModifierData *mmd= get_multires_modifier(scene, ob, 0);
+       int has_multires = mmd != NULL && mmd->sculptlvl > 0;
+
+       if(has_multires) {
+               *deformmats= NULL;
+               *deformcos= NULL;
+               return;
+       }
+
+       dm= NULL;
+       md= modifiers_getVirtualModifierList(ob);
+
+       for(; md; md= md->next) {
+               ModifierTypeInfo *mti= modifierType_getInfo(md->type);
+
+               if(!modifier_isEnabled(scene, md, eModifierMode_Realtime)) continue;
+
+               if(mti->type==eModifierTypeType_OnlyDeform && mti->deformMatrices) {
+                       if(!defmats) {
+                               Mesh *me= (Mesh*)ob->data;
+                               dm= getMeshDerivedMesh(me, ob, NULL);
+                               deformedVerts= mesh_getVertexCos(me, &numVerts);
+                               defmats= MEM_callocN(sizeof(*defmats)*numVerts, "defmats");
+
+                               for(a=0; a<numVerts; a++)
+                                       unit_m3(defmats[a]);
+                       }
+
+                       mti->deformMatrices(md, ob, dm, deformedVerts, defmats, numVerts);
+               }
+       }
+
+       if(dm)
+               dm->release(dm);
+
+       *deformmats= defmats;
+       *deformcos= deformedVerts;
+}
+
 /* ******************* GLSL ******************** */
 
 void DM_add_tangent_layer(DerivedMesh *dm)
index 71e704fe6c8d25cb22c4ec1c00e7e6417761dcf1..932be7119384ee8955b6f6cbc7ff00edaab438ec 100644 (file)
@@ -76,6 +76,7 @@ typedef struct {
        /* Cached */
        struct PBVH *pbvh;
        int pbvh_draw;
+
        /* Mesh connectivity */
        struct ListBase *fmap;
        struct IndexNode *fmap_mem;
@@ -222,6 +223,17 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
                cddm->pbvh_draw = can_pbvh_draw(ob, dm);
                BLI_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert,
                                   me->totface, me->totvert);
+
+               if(ob->sculpt->modifiers_active) {
+                       float (*vertCos)[3];
+                       int totvert;
+
+                       totvert= dm->getNumVerts(dm);
+                       vertCos= MEM_callocN(3*totvert*sizeof(float), "cdDM_getPBVH vertCos");
+                       dm->getVertCos(dm, vertCos);
+                       BLI_pbvh_apply_vertCos(cddm->pbvh, vertCos);
+                       MEM_freeN(vertCos);
+               }
        }
 
        return cddm->pbvh;
index c67abc47e6f6f38d31078a41b05805ce59e97899..2a3052d10c9123b736b99e35edfc5fda455e6809 100644 (file)
@@ -92,8 +92,10 @@ MultiresModifierData *find_multires_modifier_before(Scene *scene, ModifierData *
        return NULL;
 }
 
-/* used for applying scale on mdisps layer and syncing subdivide levels when joining objects */
-static MultiresModifierData *get_multires_modifier(Scene *scene, Object *ob)
+/* used for applying scale on mdisps layer and syncing subdivide levels when joining objects
+   use_first - return first multires modifier if all multires'es are disabled
+*/
+MultiresModifierData *get_multires_modifier(Scene *scene, Object *ob, int use_first)
 {
        ModifierData *md;
        MultiresModifierData *mmd= NULL, *firstmmd= NULL;
@@ -111,7 +113,7 @@ static MultiresModifierData *get_multires_modifier(Scene *scene, Object *ob)
                }
        }
 
-       if(!mmd) {
+       if(!mmd && use_first) {
                /* active multires have not been found
                   try to use first one */
                return firstmmd;
@@ -1568,8 +1570,8 @@ void multires_load_old(Object *ob, Mesh *me)
 
 static void multires_sync_levels(Scene *scene, Object *ob, Object *to_ob)
 {
-       MultiresModifierData *mmd= get_multires_modifier(scene, ob);
-       MultiresModifierData *to_mmd= get_multires_modifier(scene, to_ob);
+       MultiresModifierData *mmd= get_multires_modifier(scene, ob, 1);
+       MultiresModifierData *to_mmd= get_multires_modifier(scene, to_ob, 1);
 
        if(!mmd) {
                /* object could have MDISP even when there is no multires modifier
@@ -1599,7 +1601,7 @@ void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3])
        int *gridOffset;
        int i, /*numGrids,*/ gridSize, dGridSize, dSkip, totvert;
        float (*vertCos)[3] = NULL;
-       MultiresModifierData *mmd= get_multires_modifier(scene, ob);
+       MultiresModifierData *mmd= get_multires_modifier(scene, ob, 1);
        MultiresModifierData high_mmd;
 
        CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
@@ -1725,7 +1727,7 @@ void multires_topology_changed(Scene *scene, Object *ob)
        Mesh *me= (Mesh*)ob->data;
        MDisps *mdisp= NULL, *cur= NULL;
        int i, grid= 0, corners;
-       MultiresModifierData *mmd= get_multires_modifier(scene, ob);
+       MultiresModifierData *mmd= get_multires_modifier(scene, ob, 1);
 
        if(mmd)
                multires_set_tot_mdisps(me, mmd->totlvl);
index 9df55b825b7054a6dc05b027eb19b97c98a9b7de..0d3fb7107f00c273b022eada6413aca3ed99e678 100644 (file)
@@ -246,6 +246,13 @@ void free_sculptsession(Object *ob)
                if(ss->layer_co)
                        MEM_freeN(ss->layer_co);
 
+               if(ss->orig_cos)
+                       MEM_freeN(ss->orig_cos);
+               if(ss->deform_cos)
+                       MEM_freeN(ss->deform_cos);
+               if(ss->deform_imats)
+                       MEM_freeN(ss->deform_imats);
+
                MEM_freeN(ss);
 
                ob->sculpt = NULL;
index e75dc27c7b542eeb3e22fb3dc51c2c4e29a18e4a..a2d3016099d382d2f78336946b05968c1c499937 100644 (file)
@@ -70,8 +70,6 @@ static int ccgDM_getVertMapIndex(CCGSubSurf *ss, CCGVert *v);
 static int ccgDM_getEdgeMapIndex(CCGSubSurf *ss, CCGEdge *e);
 static int ccgDM_getFaceMapIndex(CCGSubSurf *ss, CCGFace *f);
 
-static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm);
-
 ///
 
 static void *arena_alloc(CCGAllocatorHDL a, int numBytes) {
@@ -1150,7 +1148,7 @@ static void ccgDM_drawVerts(DerivedMesh *dm) {
 
 static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm)
 {
-       if(ccgdm->pbvh && ccgDM_use_grid_pbvh(ccgdm)) {
+       if(ccgdm->pbvh) {
                CCGFace **faces;
                int totface;
 
@@ -2240,28 +2238,10 @@ static ListBase *ccgDM_getFaceMap(Object *ob, DerivedMesh *dm)
        return ccgdm->fmap;
 }
 
-static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm)
-{
-       ModifierData *md;
-       MultiresModifierData *mmd= ccgdm->multires.mmd;
-
-       /* in sync with sculpt mode, only use multires grid pbvh if we are
-          the last enabled modifier in the stack, otherwise we use the base
-          mesh */
-       if(!mmd)
-               return 0;
-       
-       for(md=mmd->modifier.next; md; md= md->next)
-               if(modifier_isEnabled(mmd->modifier.scene, md, eModifierMode_Realtime))
-                       return 0;
-       
-       return 1;
-}
-
 static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
 {
        CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm;
-       int gridSize, numGrids, grid_pbvh;
+       int gridSize, numGrids;
 
        if(!ob) {
                ccgdm->pbvh= NULL;
@@ -2271,21 +2251,8 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
        if(!ob->sculpt)
                return NULL;
 
-       grid_pbvh = ccgDM_use_grid_pbvh(ccgdm);
-
-       if(ob->sculpt->pbvh) {
-               if(grid_pbvh) {
-                       /* pbvh's grids, gridadj and gridfaces points to data inside ccgdm
-                          but this can be freed on ccgdm release, this updates the pointers
-                          when the ccgdm gets remade, the assumption is that the topology
-                          does not change. */
-                       ccgdm_create_grids(dm);
-                       BLI_pbvh_grids_update(ob->sculpt->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, (void**)ccgdm->gridFaces);
-               }
-
+       if(ob->sculpt->pbvh)
                ccgdm->pbvh = ob->sculpt->pbvh;
-               ccgdm->pbvh_draw = grid_pbvh;
-       }
 
        if(ccgdm->pbvh)
                return ccgdm->pbvh;
@@ -2293,25 +2260,14 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
        /* no pbvh exists yet, we need to create one. only in case of multires
           we build a pbvh over the modified mesh, in other cases the base mesh
           is being sculpted, so we build a pbvh from that. */
-       if(grid_pbvh) {
-               ccgdm_create_grids(dm);
-
-               gridSize = ccgDM_getGridSize(dm);
-               numGrids = ccgDM_getNumGrids(dm);
+       ccgdm_create_grids(dm);
 
-               ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
-               BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency,
-                       numGrids, gridSize, (void**)ccgdm->gridFaces);
-               ccgdm->pbvh_draw = 1;
-       }
-       else if(ob->type == OB_MESH) {
-               Mesh *me= ob->data;
+       gridSize = ccgDM_getGridSize(dm);
+       numGrids = ccgDM_getNumGrids(dm);
 
-               ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
-               BLI_pbvh_build_mesh(ccgdm->pbvh, me->mface, me->mvert,
-                                  me->totface, me->totvert);
-               ccgdm->pbvh_draw = 0;
-       }
+       ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
+       BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency,
+               numGrids, gridSize, (void**)ccgdm->gridFaces);
 
        return ccgdm->pbvh;
 }
index 4797aeb236473fd86cad70713c170165c27d0fff..f89068c885e8bbebc7aa6bc8254974762c2c32e6 100644 (file)
@@ -118,8 +118,6 @@ float BLI_pbvh_node_get_tmin(PBVHNode* node);
 void BLI_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
 void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
 void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *totface);
-void BLI_pbvh_grids_update(PBVH *bvh, struct DMGridData **grids,
-       struct DMGridAdjacency *gridadj, void **gridfaces);
 
 /* vertex deformer */
 float (*BLI_pbvh_get_vertCos(struct PBVH *pbvh))[3];
index 77ef825ee3425ea533fff5af996c18081abdccd1..75134358c31f5480491952c792fe73f26e502a83 100644 (file)
@@ -109,6 +109,20 @@ void copy_m4_m3(float m1[][4], float m2[][3])      /* no clear */
 
 }
 
+void swap_m3m3(float m1[][3], float m2[][3])
+{
+       float t;
+       int i, j;
+
+       for(i = 0; i < 3; i++) {
+               for (j = 0; j < 3; j++) {
+                       t        = m1[i][j];
+                       m1[i][j] = m2[i][j];
+                       m2[i][j] = t;
+               }
+       }
+}
+
 void swap_m4m4(float m1[][4], float m2[][4])
 {
        float t;
index 8727fab708640e5da2e847afd8078c2091aef74a..9be42f9f5fc47ab52e24bfeb82aa17b7d08d2330 100644 (file)
@@ -1475,13 +1475,6 @@ void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int smo
        }
 }
 
-void BLI_pbvh_grids_update(PBVH *bvh, DMGridData **grids, DMGridAdjacency *gridadj, void **gridfaces)
-{
-       bvh->grids= grids;
-       bvh->gridadj= gridadj;
-       bvh->gridfaces= gridfaces;
-}
-
 float (*BLI_pbvh_get_vertCos(PBVH *pbvh))[3]
 {
        int a;
@@ -1520,13 +1513,22 @@ void BLI_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3])
        }
 
        if (pbvh->verts) {
+               MVert *mvert= pbvh->verts;
                /* copy new verts coords */
-               for (a= 0; a < pbvh->totvert; ++a) {
-                       copy_v3_v3(pbvh->verts[a].co, vertCos[a]);
+               for (a= 0; a < pbvh->totvert; ++a, ++mvert) {
+                       copy_v3_v3(mvert->co, vertCos[a]);
+                       mvert->flag |= ME_VERT_PBVH_UPDATE;
                }
 
                /* coordinates are new -- normals should also be updated */
                mesh_calc_normals(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL);
+
+               for (a= 0; a < pbvh->totnode; ++a)
+                       BLI_pbvh_node_mark_update(&pbvh->nodes[a]);
+
+               BLI_pbvh_update(pbvh, PBVH_UpdateBB, NULL);
+               BLI_pbvh_update(pbvh, PBVH_UpdateOriginalBB, NULL);
+
        }
 }
 
index f46ab37823bb983d4fa05828ed4e22ead9e7b4da..cac6a1a2d135fb486ffb3bfeaad37f4187853f2f 100644 (file)
@@ -40,6 +40,7 @@ void ED_operatortypes_sculpt(void);
 void sculpt_get_redraw_planes(float planes[4][4], struct ARegion *ar,
                                   struct RegionView3D *rv3d, struct Object *ob);
 void ED_sculpt_force_update(struct bContext *C);
+void ED_sculpt_modifiers_changed(struct Object *ob);
 
 /* paint_ops.c */
 void ED_operatortypes_paint(void);
index 58398bd1f5c3c7955c3e313c369c62ce97e1ec5e..01f280f65724ef166412ad369e0537a7e387e4d0 100644 (file)
@@ -58,6 +58,7 @@
 #include "BKE_multires.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
+#include "BKE_lattice.h" /* for armature_deform_verts */
 
 #include "BIF_glutil.h"
 
@@ -91,12 +92,29 @@ void ED_sculpt_force_update(bContext *C)
                multires_force_update(ob);
 }
 
+void ED_sculpt_modifiers_changed(Object *ob)
+{
+       SculptSession *ss= ob->sculpt;
+
+       if(!ss->cache) {
+               /* we free pbvh on changes, except during sculpt since it can't deal with
+                  changing PVBH node organization, we hope topology does not change in
+                  the meantime .. weak */
+               if(ss->pbvh) {
+                               BLI_pbvh_free(ss->pbvh);
+                               ss->pbvh= NULL;
+               }
+
+               sculpt_free_deformMats(ob->sculpt);
+       }
+}
+
 /* Sculpt mode handles multires differently from regular meshes, but only if
    it's the last modifier on the stack and it is not on the first level */
 struct MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob)
 {
        Mesh *me= (Mesh*)ob->data;
-       ModifierData *md, *nmd;
+       ModifierData *md;
 
        if(!CustomData_get_layer(&me->fdata, CD_MDISPS)) {
                /* multires can't work without displacement layer */
@@ -107,40 +125,52 @@ struct MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob)
                if(md->type == eModifierType_Multires) {
                        MultiresModifierData *mmd= (MultiresModifierData*)md;
 
-                       /* Check if any of the modifiers after multires are active
-                        * if not it can use the multires struct */
-                       for(nmd= md->next; nmd; nmd= nmd->next)
-                               if(modifier_isEnabled(scene, nmd, eModifierMode_Realtime))
-                                       break;
+                       if(!modifier_isEnabled(scene, md, eModifierMode_Realtime))
+                               continue;
 
-                       if(!nmd && mmd->sculptlvl > 0)
-                               return mmd;
+                       if(mmd->sculptlvl > 0) return mmd;
+                       else return NULL;
                }
        }
 
        return NULL;
 }
 
-/* Checks whether full update mode (slower) needs to be used to work with modifiers */
+/* Check if there are any active modifiers in stack (used for flushing updates at enter/exit sculpt mode) */
+int sculpt_has_active_modifiers(Scene *scene, Object *ob)
+{
+       ModifierData *md;
+
+       md= modifiers_getVirtualModifierList(ob);
+
+       /* exception for shape keys because we can edit those */
+       for(; md; md= md->next) {
+               if(modifier_isEnabled(scene, md, eModifierMode_Realtime))
+                       return 1;
+       }
+
+       return 0;
+}
+
+/* Checks if there are any supported deformation modifiers active */
 int sculpt_modifiers_active(Scene *scene, Object *ob)
 {
        ModifierData *md;
        MultiresModifierData *mmd= sculpt_multires_active(scene, ob);
 
-       /* check if there are any modifiers after what we are sculpting,
-          for a multires modifier with a deform modifier in front, we
-          do no need to recalculate the modifier stack. note that this
-          needs to be in sync with ccgDM_use_grid_pbvh! */
-       if(mmd)
-               md= mmd->modifier.next;
-       else
-               md= modifiers_getVirtualModifierList(ob);
-       
+       if(mmd) return 0;
+
+       md= modifiers_getVirtualModifierList(ob);
+
        /* exception for shape keys because we can edit those */
        for(; md; md= md->next) {
-               if(modifier_isEnabled(scene, md, eModifierMode_Realtime))
-                       if(md->type != eModifierType_ShapeKey)
-                               return 1;
+               ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+               if(!modifier_isEnabled(scene, md, eModifierMode_Realtime)) continue;
+               if(md->type==eModifierType_ShapeKey) continue;
+
+               if(mti->type==eModifierTypeType_OnlyDeform && mti->deformMatrices)
+                       return 1;
        }
 
        return 0;
@@ -890,7 +920,9 @@ static void neighbor_average(SculptSession *ss, float avg[3], const unsigned ver
                
        /* Don't modify corner vertices */
        if(ncount==1) {
-               copy_v3_v3(avg, ss->mvert[vert].co);
+               if(ss->deform_cos) copy_v3_v3(avg, ss->deform_cos[vert]);
+               else copy_v3_v3(avg, ss->mvert[vert].co);
+
                return;
        }
 
@@ -906,7 +938,8 @@ static void neighbor_average(SculptSession *ss, float avg[3], const unsigned ver
 
                for(i=0; i<(f->v4?4:3); ++i) {
                        if(i != skip && (ncount!=2 || BLI_countlist(&ss->fmap[(&f->v1)[i]]) <= 2)) {
-                               add_v3_v3(avg, ss->mvert[(&f->v1)[i]].co);
+                               if(ss->deform_cos) add_v3_v3(avg, ss->deform_cos[(&f->v1)[i]]);
+                               else add_v3_v3(avg, ss->mvert[(&f->v1)[i]].co);
                                ++total;
                        }
                }
@@ -916,8 +949,10 @@ static void neighbor_average(SculptSession *ss, float avg[3], const unsigned ver
 
        if(total>0)
                mul_v3_fl(avg, 1.0f / total);
-       else
-               copy_v3_v3(avg, ss->mvert[vert].co);
+       else {
+               if(ss->deform_cos) copy_v3_v3(avg, ss->deform_cos[vert]);
+               else copy_v3_v3(avg, ss->mvert[vert].co);
+       }
 }
 
 static void do_mesh_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node, float bstrength)
@@ -2198,9 +2233,8 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3])
                ofs= key_to_vertcos(ob, kb);
 
                /* calculate key coord offsets (from previous location) */
-               for (a= 0; a < me->totvert; a++) {
+               for (a= 0; a < me->totvert; a++)
                        VECSUB(ofs[a], vertCos[a], ofs[a]);
-               }
 
                /* apply offsets on other keys */
                currkey = me->key->block.first;
@@ -2230,17 +2264,6 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3])
        vertcos_to_key(ob, kb, vertCos);
 }
 
-/* copy the modified vertices from bvh to the active key */
-static void sculpt_update_keyblock(SculptSession *ss)
-{
-       float (*vertCos)[3]= BLI_pbvh_get_vertCos(ss->pbvh);
-
-       if (vertCos) {
-               sculpt_vertcos_to_key(ss->ob, ss->kb, vertCos);
-               MEM_freeN(vertCos);
-       }
-}
-
 static void do_brush_action(Sculpt *sd, SculptSession *ss, Brush *brush)
 {
        SculptSearchSphereData data;
@@ -2326,15 +2349,6 @@ static void do_brush_action(Sculpt *sd, SculptSession *ss, Brush *brush)
                        }
                }
 
-               /* copy the modified vertices from mesh to the active key */
-               if(ss->kb)
-                       mesh_to_key(ss->ob->data, ss->kb);
-
-               /* optimization: we could avoid copying new coords to keyblock at each */
-               /* stroke step if there are no modifiers due to pbvh is used for displaying */
-               /* so to increase speed we'll copy new coords to keyblock when stroke is done */
-               if(ss->kb && ss->modifiers_active) sculpt_update_keyblock(ss);
-
                MEM_freeN(nodes);
        }
 }
@@ -2388,6 +2402,59 @@ static void sculpt_combine_proxies(Sculpt *sd, SculptSession *ss)
                MEM_freeN(nodes);
 }
 
+/* copy the modified vertices from bvh to the active key */
+static void sculpt_update_keyblock(SculptSession *ss)
+{
+       float (*vertCos)[3];
+
+       /* Keyblock update happens after hadning deformation caused by modifiers,
+          so ss->orig_cos would be updated with new stroke */
+       if(ss->orig_cos) vertCos = ss->orig_cos;
+       else vertCos = BLI_pbvh_get_vertCos(ss->pbvh);
+
+       if (vertCos) {
+               sculpt_vertcos_to_key(ss->ob, ss->kb, vertCos);
+
+               if(vertCos != ss->orig_cos)
+                       MEM_freeN(vertCos);
+       }
+}
+
+/* flush displacement from deformed PBVH to original layer */
+static void sculpt_flush_deformation(SculptSession *ss)
+{
+       float (*vertCos)[3];
+
+       vertCos= BLI_pbvh_get_vertCos(ss->pbvh);
+
+       if (vertCos) {
+               Object *ob= ss->ob;
+               Mesh *me= (Mesh*)ob->data;
+               MVert *mvert= me->mvert;
+               int a;
+
+               for(a = 0; a < me->totvert; ++a, ++mvert) {
+                       float disp[3], newco[3];
+                       sub_v3_v3v3(disp, vertCos[a], ss->deform_cos[a]);
+                       mul_m3_v3(ss->deform_imats[a], disp);
+                       add_v3_v3v3(newco, disp, ss->orig_cos[a]);
+
+                       copy_v3_v3(ss->deform_cos[a], vertCos[a]);
+                       copy_v3_v3(ss->orig_cos[a], newco);
+
+                       if(!ss->kb)
+                               copy_v3_v3(mvert->co, newco);
+               }
+
+               if(ss->kb)
+                       sculpt_update_keyblock(ss);
+
+               mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+
+               MEM_freeN(vertCos);
+       }
+}
+
 //static int max_overlap_count(Sculpt *sd)
 //{
 //     int count[3];
@@ -2496,6 +2563,9 @@ static void do_symmetrical_brush_actions(Sculpt *sd, SculptSession *ss)
        /* hack to fix noise texture tearing mesh */
        sculpt_fix_noise_tear(sd, ss);
 
+       if (ss->modifiers_active)
+               sculpt_flush_deformation(ss);
+
        cache->first_time= 0;
 }
 
@@ -2517,6 +2587,17 @@ static void sculpt_update_tex(Sculpt *sd, SculptSession *ss)
        }
 }
 
+void sculpt_free_deformMats(SculptSession *ss)
+{
+       if(ss->orig_cos) MEM_freeN(ss->orig_cos);
+       if(ss->deform_cos) MEM_freeN(ss->deform_cos);
+       if(ss->deform_imats) MEM_freeN(ss->deform_imats);
+
+       ss->orig_cos = NULL;
+       ss->deform_cos = NULL;
+       ss->deform_imats = NULL;
+}
+
 void sculpt_update_mesh_elements(Scene *scene, Object *ob, int need_fmap)
 {
        DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
@@ -2551,6 +2632,23 @@ void sculpt_update_mesh_elements(Scene *scene, Object *ob, int need_fmap)
        ss->pbvh = dm->getPBVH(ob, dm);
        ss->fmap = (need_fmap && dm->getFaceMap)? dm->getFaceMap(ob, dm): NULL;
 
+       if(ss->modifiers_active) {
+               if(!ss->orig_cos) {
+                       int a;
+
+                       sculpt_free_deformMats(ss);
+
+                       if(ss->kb) ss->orig_cos = key_to_vertcos(ob, ss->kb);
+                       else ss->orig_cos = mesh_getVertexCos(ob->data, NULL);
+
+                       sculpt_get_deform_matrices(scene, ob, &ss->deform_imats, &ss->deform_cos);
+                       BLI_pbvh_apply_vertCos(ss->pbvh, ss->deform_cos);
+
+                       for(a = 0; a < ((Mesh*)ob->data)->totvert; ++a)
+                               invert_m3(ss->deform_imats[a]);
+               }
+       } else sculpt_free_deformMats(ss);
+
        /* if pbvh is deformed, key block is already applied to it */
        if (ss->kb && !BLI_pbvh_isDeformed(ss->pbvh)) {
                float (*vertCos)[3]= key_to_vertcos(ob, ss->kb);
@@ -2792,8 +2890,12 @@ static void sculpt_update_cache_invariants(bContext* C, Sculpt *sd, SculptSessio
                                ss->layer_co= MEM_mallocN(sizeof(float) * 3 * ss->totvert,
                                                                           "sculpt mesh vertices copy");
 
-                       for(i = 0; i < ss->totvert; ++i)
-                               copy_v3_v3(ss->layer_co[i], ss->mvert[i].co);
+                       if(ss->deform_cos) memcpy(ss->layer_co, ss->deform_cos, ss->totvert);
+                       else {
+                               for(i = 0; i < ss->totvert; ++i) {
+                                       copy_v3_v3(ss->layer_co[i], ss->mvert[i].co);
+                               }
+                       }
                }
        }
 
@@ -3214,7 +3316,6 @@ static void sculpt_flush_update(bContext *C)
                rcti r;
 
                BLI_pbvh_update(ss->pbvh, PBVH_UpdateBB, NULL);
-
                if (sculpt_get_redraw_rect(ar, CTX_wm_region_view3d(C), ob, &r)) {
                        //rcti tmp;
 
@@ -3489,7 +3590,7 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *unused)
        /* multires in sculpt mode could have different from object mode subdivision level */
        flush_recalc |= mmd && mmd->sculptlvl != mmd->lvl;
        /* if object has got active modifiers, it's dm could be different in sculpt mode  */
-       //flush_recalc |= sculpt_modifiers_active(scene, ob);
+       flush_recalc |= sculpt_has_active_modifiers(scene, ob);
 
        if(ob->mode & OB_MODE_SCULPT) {
                if(mmd)
@@ -3554,4 +3655,3 @@ void ED_operatortypes_sculpt(void)
        WM_operatortype_append(SCULPT_OT_sculptmode_toggle);
        WM_operatortype_append(SCULPT_OT_set_persistent_base);
 }
-
index a48d6d8d9c9e21e46bb9a4cae4a837e46a31337a..76a7349606c448c506f8e9032ad2ddd61ec59076 100644 (file)
@@ -61,6 +61,9 @@ void sculpt(Sculpt *sd);
 int sculpt_poll(struct bContext *C);
 void sculpt_update_mesh_elements(struct Scene *scene, struct Object *ob, int need_fmap);
 
+/* Deformed mesh sculpt */
+void sculpt_free_deformMats(struct SculptSession *ss);
+
 /* Stroke */
 struct SculptStroke *sculpt_stroke_new(const int max);
 void sculpt_stroke_free(struct SculptStroke *);
@@ -78,6 +81,7 @@ typedef struct SculptUndoNode {
        void *node;                                     /* only during push, not valid afterwards! */
 
        float (*co)[3];
+       float (*orig_co)[3];
        short (*no)[3];
        int totvert;
 
index a8fee6ea39de5bb90d86feb4271f3566eb35a536..d136fdaf6e0b4affbc222620b536da10b6b352c1 100644 (file)
@@ -67,6 +67,12 @@ static void update_cb(PBVHNode *node, void *unused)
        BLI_pbvh_node_mark_update(node);
 }
 
+static void sculpt_restore_deformed(SculptSession *ss, SculptUndoNode *unode, int uindex, int oindex, float coord[3])
+{
+       swap_v3_v3(coord, unode->orig_co[uindex]);
+       copy_v3_v3(unode->co[uindex], ss->deform_cos[oindex]);
+}
+
 static void sculpt_undo_restore(bContext *C, ListBase *lb)
 {
        Scene *scene = CTX_data_scene(C);
@@ -117,8 +123,10 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
                                float (*vertCos)[3];
                                vertCos= key_to_vertcos(ob, ss->kb);
 
-                               for(i=0; i<unode->totvert; i++)
-                                       swap_v3_v3(vertCos[index[i]], unode->co[i]);
+                               for(i=0; i<unode->totvert; i++) {
+                                       if(ss->modifiers_active) sculpt_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]);
+                                       else swap_v3_v3(vertCos[index[i]], unode->co[i]);
+                               }
 
                                /* propagate new coords to keyblock */
                                sculpt_vertcos_to_key(ob, ss->kb, vertCos);
@@ -130,7 +138,8 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
                                MEM_freeN(vertCos);
                        } else {
                                for(i=0; i<unode->totvert; i++) {
-                                       swap_v3_v3(mvert[index[i]].co, unode->co[i]);
+                                       if(ss->modifiers_active) sculpt_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
+                                       else swap_v3_v3(mvert[index[i]].co, unode->co[i]);
                                        mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
                                }
                        }
@@ -162,6 +171,7 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
        }
 
        if(update) {
+               int tag_update= 0;
                /* we update all nodes still, should be more clever, but also
                   needs to work correct when exiting/entering sculpt mode and
                   the nodes get recreated, though in that case it could do all */
@@ -171,7 +181,14 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
                if((mmd=sculpt_multires_active(scene, ob)))
                        multires_mark_as_modified(ob);
 
-               if(ss->modifiers_active || ((Mesh*)ob->data)->id.us > 1)
+               tag_update= ((Mesh*)ob->data)->id.us > 1;
+
+               if(ss->modifiers_active) {
+                       sculpt_free_deformMats(ss);
+                       tag_update|= 1;
+               }
+
+               if(tag_update)
                        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 
                /* for non-PBVH drawing, need to recreate VBOs */
@@ -194,6 +211,8 @@ static void sculpt_undo_free(ListBase *lb)
                        MEM_freeN(unode->grids);
                if(unode->layer_disp)
                        MEM_freeN(unode->layer_disp);
+               if(unode->orig_co)
+                       MEM_freeN(unode->orig_co);
        }
 }
 
@@ -255,6 +274,9 @@ SculptUndoNode *sculpt_undo_push_node(SculptSession *ss, PBVHNode *node)
                unode->index= MEM_mapallocN(sizeof(int)*allvert, "SculptUndoNode.index");
        }
 
+       if(ss->modifiers_active)
+               unode->orig_co= MEM_callocN(allvert*sizeof(*unode->orig_co), "undoSculpt orig_cos");
+
        BLI_unlock_thread(LOCK_CUSTOM1);
 
        /* copy threaded, hopefully this is the performance critical part */
@@ -266,6 +288,9 @@ SculptUndoNode *sculpt_undo_push_node(SculptSession *ss, PBVHNode *node)
                        if(vd.no) VECCOPY(unode->no[vd.i], vd.no)
                        else normal_float_to_short_v3(unode->no[vd.i], vd.fno);
                        if(vd.vert_indices) unode->index[vd.i]= vd.vert_indices[vd.i];
+
+                       if(ss->modifiers_active)
+                               copy_v3_v3(unode->orig_co[vd.i], ss->orig_cos[unode->index[vd.i]]);
                }
                BLI_pbvh_vertex_iter_end;
        }
index d06ec92d4dfa0185037eae58caedc3459871fc8a..ac25987871dd16d0591b551cdb2341ca0410e03b 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "DNA_armature_types.h"
 #include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
 
 #include "BLI_utildefines.h"
 
@@ -161,6 +162,19 @@ static void deformMatricesEM(
        if(!derivedData) dm->release(dm);
 }
 
+static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
+                                                  float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
+{
+       ArmatureModifierData *amd = (ArmatureModifierData*) md;
+       DerivedMesh *dm = derivedData;
+
+       if(!derivedData) dm = CDDM_from_mesh((Mesh*)ob->data, ob);
+
+       armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
+                                 amd->deformflag, NULL, amd->defgrp_name);
+
+       if(!derivedData) dm->release(dm);
+}
 
 ModifierTypeInfo modifierType_Armature = {
        /* name */              "Armature",
@@ -172,6 +186,7 @@ ModifierTypeInfo modifierType_Armature = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    deformMatrices,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  deformMatricesEM,
        /* applyModifier */     0,
index f6d497b763feb6b81fb2301bcb775779b547456b..1fdfe6c192c892d0f4dd1e61bde63bf95d6f5ed1 100644 (file)
@@ -807,6 +807,7 @@ ModifierTypeInfo modifierType_Array = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index e775d7e426220806a3014672737afc5f33cb78a8..effc376943ea83e24346a82e8807b8a5aaf677bc 100644 (file)
@@ -129,6 +129,7 @@ ModifierTypeInfo modifierType_Bevel = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 112618a2bd6cdfebcb284385d21c67617be69240..c40d6cfb79eea434ef25e8ee8326bed5c0203760 100644 (file)
@@ -139,6 +139,7 @@ ModifierTypeInfo modifierType_Boolean = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 1588d1f44d55e4a023f812f25bfd25a10515d621..704caf0aff8d0fe76ef42c36a6e15fe595b7028e 100644 (file)
@@ -287,6 +287,7 @@ ModifierTypeInfo modifierType_Build = {
                                                        | eModifierTypeFlag_AcceptsCVs,
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index c3400a6541db4f4d7453b8312b277a75d111bd45..17c2ec40b7edd7c25d8f23a99fbf945bbd8b5309 100644 (file)
@@ -619,6 +619,7 @@ ModifierTypeInfo modifierType_Cast = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index a0566d32c73cc9c3a1371e043d055d6d6d6a6e69..1cb46c0992f1e971de5c35243387fa206736091f 100644 (file)
@@ -196,6 +196,7 @@ ModifierTypeInfo modifierType_Cloth = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index bf3240304249d9886a0e36664e95c2efa559ba04..8decb460d6a8baef3489c3773d415c7d538df695 100644 (file)
@@ -243,6 +243,7 @@ ModifierTypeInfo modifierType_Collision = {
 
        /* copyData */          0,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index b1a5965cbe309088fb0087c53ce16c5267cc24d1..c4e41941acce94f0a0ef413ac10c417447edb05a 100644 (file)
@@ -142,6 +142,7 @@ ModifierTypeInfo modifierType_Curve = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 7903e1adb47284a301f0f08383678adbe350949a..2f1723cf9bbb7a88a78d40a976f28a75557e8fb6 100644 (file)
@@ -197,6 +197,7 @@ ModifierTypeInfo modifierType_Decimate = {
        /* flags */             eModifierTypeFlag_AcceptsMesh,
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 931865409cbb8abcda81859c26a7b55446adeaa4..919814edf59f93fd7f40712f02d1f7278fb777bc 100644 (file)
@@ -357,6 +357,7 @@ ModifierTypeInfo modifierType_Displace = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 105e4777e87b0148173563159892d8713df45700..561385520003a9a6be428c29e50247d27187a8fc 100644 (file)
@@ -1278,6 +1278,7 @@ ModifierTypeInfo modifierType_EdgeSplit = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index e6a3dc496681d05fcc2456bbaff417926ec4f5e6..a0765b56808a3ee531f5b4e6e290bb9c4de11882 100644 (file)
@@ -895,6 +895,7 @@ ModifierTypeInfo modifierType_Explode = {
        /* flags */             eModifierTypeFlag_AcceptsMesh,
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index bbb88ba09e3bc4e21d454814f6a73da2823f4900..19111b0cafc72c930355ab0b1b8088f85169d1f4 100644 (file)
@@ -142,6 +142,7 @@ ModifierTypeInfo modifierType_Fluidsim = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index adf198824198ffde382df3adb3fbcc2014473226..79493d2c549dd2a21865f7a5ac68cb28eeeda388 100644 (file)
@@ -284,6 +284,7 @@ ModifierTypeInfo modifierType_Hook = {
                                                        | eModifierTypeFlag_SupportsEditmode,
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 136998dbc78179e9356af77c4ab3d973a0a24893..c5fb87c8ffc08c7953c281e2af05d10a4e058ec4 100644 (file)
@@ -137,6 +137,7 @@ ModifierTypeInfo modifierType_Lattice = {
                                                        | eModifierTypeFlag_SupportsEditmode,
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 05a7bbecaea5847de9e06d0b03230a7f418c17a3..b2f2c86c46d6fd557bd3a71f7b3a7aff1aa1b22b 100644 (file)
@@ -399,6 +399,7 @@ ModifierTypeInfo modifierType_Mask = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 6df57bf372e43858e6dd44f112f8edf0d0919be1..61e7f950e0f0d5cffef554a166f6e73b8032d2db 100644 (file)
@@ -445,6 +445,7 @@ ModifierTypeInfo modifierType_MeshDeform = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index c07bd10d6fab35a9e87f6b35143bb056bc284615..9546bf1300b95fd36887220f435a676d9c503012 100644 (file)
@@ -338,6 +338,7 @@ ModifierTypeInfo modifierType_Mirror = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 96dcde121808cf0e5c12814f56e5416301dccd2b..10b135aaa776ac5e207f36055ca25a704c0e19cc 100644 (file)
@@ -109,6 +109,7 @@ ModifierTypeInfo modifierType_Multires = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index cc27d3b659b33d8d8d4c616e7ec35e33a373a63a..c08335d638a64d452306541594223e6d4c3d3131 100644 (file)
@@ -59,6 +59,7 @@ ModifierTypeInfo modifierType_None = {
 
        /* copyData */          0,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index f0e7699c2926b82b7be186c56ebfdf44fd26ae12..c36581d9317bb604f5a1b42c85ccabef07dc708d 100644 (file)
@@ -330,6 +330,7 @@ ModifierTypeInfo modifierType_ParticleInstance = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 9b77a90488716a11d062c4459e4883e9a6a046b5..c7638afbbcc422d7497fc34e9c2a9117ea8b7955 100644 (file)
@@ -229,6 +229,7 @@ ModifierTypeInfo modifierType_ParticleSystem = {
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
        /* deformVertsEM */     0 /* deformVertsEM */ ,
+       /* deformMatrices */    0,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
        /* applyModifierEM */   0,
index 96e1c6c0d01662c0d2d6602143d5540728831b37..7e8fad2801e8865239ba8d14bc9988619375a31a 100644 (file)
@@ -884,6 +884,7 @@ ModifierTypeInfo modifierType_Screw = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 5466d240dd25e14264b0b85ef0db78a3042ef18e..e03783e8eebbb6f85d6df8d9690216bf9be66457 100644 (file)
@@ -64,6 +64,27 @@ static void deformVerts(ModifierData *md, Object *ob,
        }
 }
 
+static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
+                                                  float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
+{
+       Key *key= ob_get_key(ob);
+       KeyBlock *kb= ob_get_keyblock(ob);
+       float scale[3][3];
+       int a;
+
+       (void)vertexCos; /* unused */
+
+       if(kb && kb->totelem==numVerts && kb!=key->refkey) {
+               if(ob->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1);
+               else scale_m3_fl(scale, kb->curval);
+
+               for(a=0; a<numVerts; a++)
+                       copy_m3_m3(defMats[a], scale);
+       }
+
+       deformVerts(md, ob, derivedData, vertexCos, numVerts, 0, 0);
+}
+
 static void deformVertsEM(ModifierData *md, Object *ob,
                                                struct EditMesh *UNUSED(editData),
                                                DerivedMesh *derivedData,
@@ -87,7 +108,7 @@ static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob,
        KeyBlock *kb= ob_get_keyblock(ob);
        float scale[3][3];
        int a;
-       
+
        (void)vertexCos; /* unused */
 
        if(kb && kb->totelem==numVerts && kb!=key->refkey) {
@@ -98,7 +119,6 @@ static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob,
        }
 }
 
-
 ModifierTypeInfo modifierType_ShapeKey = {
        /* name */              "ShapeKey",
        /* structName */        "ShapeKeyModifierData",
@@ -109,6 +129,7 @@ ModifierTypeInfo modifierType_ShapeKey = {
 
        /* copyData */          0,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    deformMatrices,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  deformMatricesEM,
        /* applyModifier */     0,
index a7de27c0bf6831275269ae00468054deea3bf26d..56a5b4b8577848985d2e6a7b1a4452831830506a 100644 (file)
@@ -167,6 +167,7 @@ ModifierTypeInfo modifierType_Shrinkwrap = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 003b206f9bc01bc10bb7bbc1bedaa712d869d3db..1c3e40a4193533848fb62be4e4af6b1c59307d8c 100644 (file)
@@ -375,6 +375,7 @@ ModifierTypeInfo modifierType_SimpleDeform = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 2edfee7e6e458c35f3b82ae2839d8d8422c24dfc..0227d2008e598c7e652b39b4b6aaca6dc617a5ae 100644 (file)
@@ -154,6 +154,7 @@ ModifierTypeInfo modifierType_Smoke = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index bc04b253cecd7d97adbf188223b28a525f284ce0..7761995a419ed8d31d9be9983133601a7b248244 100644 (file)
@@ -256,6 +256,7 @@ ModifierTypeInfo modifierType_Smooth = {
 
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 24af10fde2b610d3bc311126241b5bd0a3a5e288..7322628267c9eae43eff973300250c65a2e00b38 100644 (file)
@@ -68,6 +68,7 @@ ModifierTypeInfo modifierType_Softbody = {
 
        /* copyData */          0,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 6485076bde4bb7ec428287e216038f6a3301523b..4faf955b953f38dc2f61f32bbe0f107aeb9e1ee1 100644 (file)
@@ -651,6 +651,7 @@ ModifierTypeInfo modifierType_Solidify = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 1238c891f331574e5bcbaa9a7206a6eb60030818..4ba139305d8868da5b37b1e48493513f42d99f98 100644 (file)
@@ -133,6 +133,7 @@ ModifierTypeInfo modifierType_Subsurf = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index d68ba84d58b4eccb177f128a272ee7e0d7334e83..8d6f6954e18d7eb2e23f12f3b76b8cb7b6fe032d 100644 (file)
@@ -173,6 +173,7 @@ ModifierTypeInfo modifierType_Surface = {
 
        /* copyData */          0,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 3f43924d6a2d8f87880774e8b99f41039dc17e2e..8eaf0d5fbcbb991e526a49fee9ac8141ce7ffb50 100644 (file)
@@ -413,6 +413,7 @@ ModifierTypeInfo modifierType_UVProject = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
index 69c9f1165ce5e6c18e2899ce1e60a0ae84fae0fc..dae9fc471cde43fd8955b86dcca311ca82ed2dd9 100644 (file)
@@ -452,6 +452,7 @@ ModifierTypeInfo modifierType_Wave = {
                                                        | eModifierTypeFlag_SupportsEditmode,
        /* copyData */          copyData,
        /* deformVerts */       deformVerts,
+       /* deformMatrices */    0,
        /* deformVertsEM */     deformVertsEM,
        /* deformMatricesEM */  0,
        /* applyModifier */     0,
index 5fd58128f6ad4c8ad4a6c5f75557bca5e8514ab1..c831c2a477e5811ab467ac29fdf04679c2c5fbff 100644 (file)
@@ -431,6 +431,7 @@ float sculpt_get_brush_unprojected_radius(struct Brush *brush){return 0.0f;}
 void sculpt_set_brush_unprojected_radius(struct Brush *brush, float unprojected_radius){}
 float sculpt_get_brush_alpha(struct Brush *brush){return 0.0f;}
 void sculpt_set_brush_alpha(struct Brush *brush, float alpha){}
+void ED_sculpt_modifiers_changed(struct Object *ob){};
 
 char blender_path[] = "";