Bugfix: Copy Modifiers with particle systems crashed, it didn't copy
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 27 Feb 2008 17:04:58 +0000 (17:04 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 27 Feb 2008 17:04:58 +0000 (17:04 +0000)
the particle systems.

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/object.c
source/blender/src/editobject.c

index 0a4c9a04815e1e4eb7aff3d8af20501d7e1e61e4..903ca7a66aaa8917adf3671f5098c7f1a69abef9 100644 (file)
@@ -51,6 +51,10 @@ void clear_workob(void);
 void copy_baseflags(void);
 void copy_objectflags(void);
 struct SoftBody *copy_softbody(struct SoftBody *sb);
+void copy_object_particlesystems(struct Object *obn, struct Object *ob);
+void copy_object_softbody(struct Object *obn, struct Object *ob);
+void object_free_particlesystems(struct Object *ob);
+void object_free_softbody(struct Object *ob);
 void update_base_layer(struct Object *ob);
 
 void free_object(struct Object *ob);
index f67dd7c81fe10b600395c84fa7d8f6558e3e5d7b..cc54ced4b4d6a37d907e73114b896680f842023e 100644 (file)
@@ -5412,6 +5412,7 @@ static void particleSystemModifier_copyData(ModifierData *md, ModifierData *targ
        ParticleSystemModifierData *tpsmd= (ParticleSystemModifierData*) target;
 
        tpsmd->dm = 0;
+       tpsmd->totdmvert = tpsmd->totdmedge = tpsmd->totdmface = 0;
        //tpsmd->facepa = 0;
        tpsmd->flag = psmd->flag;
        /* need to keep this to recognise a bit later in copy_object */
index 16934783a07a97c1d4b98dc2443b8ea696a2a599..3f1515f146a857e2468182f2b9afe4f9ebe3fe1c 100644 (file)
@@ -157,6 +157,25 @@ void update_base_layer(Object *ob)
        }
 }
 
+void object_free_particlesystems(Object *ob)
+{
+       while(ob->particlesystem.first){
+               ParticleSystem *psys = ob->particlesystem.first;
+
+               BLI_remlink(&ob->particlesystem,psys);
+
+               psys_free(ob,psys);
+       }
+}
+
+void object_free_softbody(Object *ob)
+{
+       if(ob->soft) {
+               sbFree(ob->soft);
+               ob->soft= NULL;
+       }
+}
+
 void object_free_modifiers(Object *ob)
 {
        while (ob->modifiers.first) {
@@ -168,13 +187,10 @@ void object_free_modifiers(Object *ob)
        }
 
        /* particle modifiers were freed, so free the particlesystems as well */
-       while(ob->particlesystem.first){
-               ParticleSystem *psys = ob->particlesystem.first;
-
-               BLI_remlink(&ob->particlesystem,psys);
+       object_free_particlesystems(ob);
 
-               psys_free(ob,psys);
-       }
+       /* same for softbody */
+       object_free_softbody(ob);
 }
 
 /* here we will collect all local displist stuff */
@@ -1034,6 +1050,35 @@ ParticleSystem *copy_particlesystem(ParticleSystem *psys)
        return psysn;
 }
 
+void copy_object_particlesystems(Object *obn, Object *ob)
+{
+       ParticleSystemModifierData *psmd;
+       ParticleSystem *psys, *npsys;
+       ModifierData *md;
+
+       obn->particlesystem.first= obn->particlesystem.last= NULL;
+       for(psys=ob->particlesystem.first; psys; psys=psys->next) {
+               npsys= copy_particlesystem(psys);
+
+               BLI_addtail(&obn->particlesystem, npsys);
+
+               /* need to update particle modifiers too */
+               for(md=obn->modifiers.first; md; md=md->next) {
+                       if(md->type==eModifierType_ParticleSystem) {
+                               psmd= (ParticleSystemModifierData*)md;
+                               if(psmd->psys==psys)
+                                       psmd->psys= npsys;
+                       }
+               }
+       }
+}
+
+void copy_object_softbody(Object *obn, Object *ob)
+{
+       if(ob->soft)
+               obn->soft= copy_softbody(ob->soft);
+}
+
 static void copy_object_pose(Object *obn, Object *ob)
 {
        bPoseChannel *chan;
@@ -1077,7 +1122,6 @@ Object *copy_object(Object *ob)
 {
        Object *obn;
        ModifierData *md;
-       ParticleSystem *psys;
        int a;
 
        obn= copy_libblock(ob);
@@ -1144,22 +1188,7 @@ Object *copy_object(Object *ob)
                }
        }
 
-       obn->particlesystem.first= obn->particlesystem.last= NULL;
-       for(psys=ob->particlesystem.first; psys; psys=psys->next) {
-               ParticleSystemModifierData *psmd;
-               ParticleSystem *npsys= copy_particlesystem(psys);
-
-               BLI_addtail(&obn->particlesystem, npsys);
-
-               /* need to update particle modifiers too */
-               for(md=obn->modifiers.first; md; md=md->next) {
-                       if(md->type==eModifierType_ParticleSystem) {
-                               psmd= (ParticleSystemModifierData*)md;
-                               if(psmd->psys==psys)
-                                       psmd->psys= npsys;
-                       }
-               }
-       }
+       copy_object_particlesystems(obn, ob);
        
        obn->derivedDeform = NULL;
        obn->derivedFinal = NULL;
index e6edb472fc33dea4dd51e5e9215c65c5ae95f54c..6084ece8c6eeaf0228c3a0c7978a7b926009aaf6 100644 (file)
@@ -3079,7 +3079,7 @@ static void copymenu_modifiers(Object *ob)
        for (i=eModifierType_None+1; i<NUM_MODIFIER_TYPES; i++) {
                ModifierTypeInfo *mti = modifierType_getInfo(i);
 
-               if (ELEM(i, eModifierType_Hook, eModifierType_Softbody)) continue;
+               if(ELEM3(i, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance)) continue;
 
                if (    (mti->flags&eModifierTypeFlag_AcceptsCVs) || 
                                (ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {
@@ -3109,6 +3109,9 @@ static void copymenu_modifiers(Object *ob)
                                                                BLI_addtail(&base->object->modifiers, nmd);
                                                        }
                                                }
+
+                                               copy_object_particlesystems(base->object, ob);
+                                               copy_object_softbody(base->object, ob);
                                        } else {
                                                /* copy specific types */
                                                ModifierData *md, *mdn;
@@ -3132,6 +3135,15 @@ static void copymenu_modifiers(Object *ob)
                                                                modifier_copyData(md, mdn);
                                                        }
                                                }
+
+                                               if(event == eModifierType_ParticleSystem) {
+                                                       object_free_particlesystems(base->object);
+                                                       copy_object_particlesystems(base->object, ob);
+                                               }
+                                               else if(event == eModifierType_Softbody) {
+                                                       object_free_softbody(base->object);
+                                                       copy_object_softbody(base->object, ob);
+                                               }
                                        }
                                }
                                else