Shift+O subdivision switching now also allows to switch
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 17 Dec 2007 12:54:39 +0000 (12:54 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 17 Dec 2007 12:54:39 +0000 (12:54 +0000)
particle systems on/off if they exist.

source/blender/blenkernel/intern/DerivedMesh.c
source/blender/src/buttons_editing.c
source/blender/src/editobject.c

index 61ad1bd0ebf3d1c1060237d0e84eb90f041565c2..dd56fe2df6123b1176afc09e7440b1766eb6102a 100644 (file)
@@ -2099,7 +2099,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3],
                }
        }
 
-       for(md=first; md; md=md->next)
+       for(md=firstmd; md; md=md->next)
                modifier_freeTemporaryData(md);
 
        /* Yay, we are done. If we have a DerivedMesh and deformed vertices
index 116a2c117d2f1eae7f195a03f56664ca4c7004ad..92ee7af26cc99889bb4bad885ff7714d097d5557 100644 (file)
@@ -1639,7 +1639,7 @@ void modifiers_explodeFacepa(void *arg1, void *arg2)
        emd->flag |= eExplodeFlag_CalcFaces;
 }
 
-static void modifiers_psysEnable(void *ob_v, void *md_v)
+void modifiers_psysEnable(void *ob_v, void *md_v)
 {
        ParticleSystemModifierData *psmd = (ParticleSystemModifierData*) md_v;
 
index 193bd0f46c43e8ed766bd61e4e15e7713c1e2b45..7e88c8278b5a5048cbb330743b88ca60c19f220a 100644 (file)
@@ -2818,54 +2818,90 @@ void convertmenu(void)
        DAG_scene_sort(G.scene);
 }
 
-       /* Change subdivision properties of mesh object ob, if
-        * level==-1 then toggle subsurf, else set to level.
-     * *set allows to toggle multiple selections
-        */
-static void object_flip_subdivison(Object *ob, int *set, int level, int mode, int ingroup)
+/* Change subdivision or particle properties of mesh object ob, if level==-1
+ * then toggle subsurf, else set to level set allows to toggle multiple
+ * selections */
+
+static void object_has_subdivision_particles(Object *ob, int *havesubdiv, int *havepart, int depth)
 {
+       if(ob->type==OB_MESH) {
+               if(modifiers_findByType(ob, eModifierType_Subsurf))
+                       *havesubdiv= 1;
+               if(modifiers_findByType(ob, eModifierType_ParticleSystem))
+                       *havepart= 1;
+       }
+
+       if(ob->dup_group && depth <= 4) {
+               GroupObject *go;
+
+               for(go= ob->dup_group->gobject.first; go; go= go->next)
+                       object_has_subdivision_particles(go->ob, havesubdiv, havepart, depth+1);
+       }
+}
+
+static void object_flip_subdivison_particles(Object *ob, int *set, int level, int mode, int particles, int depth)
+{
+       void modifiers_psysEnable(void *ob_v, void *md_v);
        ModifierData *md;
 
        if(ob->type==OB_MESH) {
-               md = modifiers_findByType(ob, eModifierType_Subsurf);
-               
-               if (md) {
-                       SubsurfModifierData *smd = (SubsurfModifierData*) md;
-
-                       if (level == -1) {
-                               if(*set == -1) 
-                                       *set= smd->modifier.mode&(mode);
-                                                                                         
-                               if (*set) {
-                                       smd->modifier.mode &= ~(mode);
-                               } else {
-                                       smd->modifier.mode |= (mode);
+               if(particles) {
+                       for(md=ob->modifiers.first; md; md=md->next) {
+                               if(md->type == eModifierType_ParticleSystem) {
+                                       ParticleSystemModifierData *psmd = (ParticleSystemModifierData*)md;
+
+                                       if(*set == -1)
+                                               *set= psmd->modifier.mode&(mode);
+
+                                       if (*set)
+                                               psmd->modifier.mode &= ~(mode);
+                                       else
+                                               psmd->modifier.mode |= (mode);
+
+                                       modifiers_psysEnable(ob, md);
                                }
-                       } else {
-                               smd->levels = level;
                        }
-               } 
-               else if(!ingroup && *set != 0) {
-                       SubsurfModifierData *smd = (SubsurfModifierData*) modifier_new(eModifierType_Subsurf);
+               }
+               else {
+                       md = modifiers_findByType(ob, eModifierType_Subsurf);
+
+                       if (md) {
+                               SubsurfModifierData *smd = (SubsurfModifierData*) md;
 
-                       BLI_addtail(&ob->modifiers, smd);
+                               if (level == -1) {
+                                       if(*set == -1) 
+                                               *set= smd->modifier.mode&(mode);
 
-                       if (level!=-1) {
-                               smd->levels = level;
+                                       if (*set)
+                                               smd->modifier.mode &= ~(mode);
+                                       else
+                                               smd->modifier.mode |= (mode);
+                               } else {
+                                       smd->levels = level;
+                               }
+                       } 
+                       else if(depth == 0 && *set != 0) {
+                               SubsurfModifierData *smd = (SubsurfModifierData*) modifier_new(eModifierType_Subsurf);
+
+                               BLI_addtail(&ob->modifiers, smd);
+
+                               if (level!=-1) {
+                                       smd->levels = level;
+                               }
+                               
+                               if(*set == -1)
+                                       *set= 1;
                        }
-                       
-                       if(*set == -1)
-                               *set= 1;
                }
 
-               ob->recalc |= OB_RECALC_DATA;
+               DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
        }
 
-       if(ob->dup_group) {
+       if(ob->dup_group && depth<=4) {
                GroupObject *go;
 
                for(go= ob->dup_group->gobject.first; go; go= go->next)
-                       object_flip_subdivison(go->ob, set, level, mode, 1);
+                       object_flip_subdivison_particles(go->ob, set, level, mode, particles, depth+1);
        }
 }
 
@@ -2877,16 +2913,34 @@ void flip_subdivison(int level)
 {
        Base *base;
        int set= -1;
-       int mode;
+       int mode, pupmode, particles= 0, havesubdiv= 0, havepart= 0;
        
        if(G.qual & LR_ALTKEY)
                mode= eModifierMode_Realtime;
        else
                mode= eModifierMode_Render|eModifierMode_Realtime;
        
+       if(level == -1) {
+               for(base= G.scene->base.first; base; base= base->next)
+                       if(((level==-1) && (TESTBASE(base))) || (TESTBASELIB(base)))
+                               object_has_subdivision_particles(base->object, &havesubdiv, &havepart, 0);
+       }
+       else
+               havesubdiv= 1;
+       
+       if(havesubdiv && havepart) {
+               pupmode= pupmenu("Switch%t|Subsurf %x1|Particle Systems %x2");
+               if(pupmode <= 0)
+                       return;
+               else if(pupmode == 2)
+                       particles= 1;
+       }
+       else if(havepart)
+               particles= 1;
+       
        for(base= G.scene->base.first; base; base= base->next)
                if(((level==-1) && (TESTBASE(base))) || (TESTBASELIB(base)))
-                       object_flip_subdivison(base->object, &set, level, mode, 0);
+                       object_flip_subdivison_particles(base->object, &set, level, mode, particles, 0);
        
        countall();
        allqueue(REDRAWVIEW3D, 0);
@@ -2895,7 +2949,10 @@ void flip_subdivison(int level)
        allqueue(REDRAWBUTSOBJECT, 0);
        DAG_scene_flush_update(G.scene, screen_view3d_layers());
        
-       BIF_undo_push("Switch subsurf on/off");
+       if(particles)
+               BIF_undo_push("Switch particles on/off");
+       else
+               BIF_undo_push("Switch subsurf on/off");
 }
  
 static void copymenu_properties(Object *ob)