Add id looper for particlesystem.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 8 Oct 2015 12:56:20 +0000 (14:56 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 8 Oct 2015 13:05:37 +0000 (15:05 +0200)
source/blender/blenkernel/BKE_particle.h
source/blender/blenkernel/intern/library_query.c
source/blender/blenkernel/intern/particle_system.c

index 89cfb3a2aac31eff564218cdb19e9e1977f3b91a..00cc48cf713b67b1a19c96cef0b9e9dd9b377ad8 100644 (file)
@@ -378,6 +378,11 @@ void psys_get_birth_coords(struct ParticleSimulationData *sim, struct ParticleDa
 
 void particle_system_update(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
 
+/* Callback format for performing operations on ID-pointers for particle systems */
+typedef void (*ParticleSystemIDFunc)(struct ParticleSystem *psys, struct ID **idpoin, void *userdata, int cd_flag);
+
+void BKE_particlesystem_id_loop(struct ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata);
+
 /* ----------- functions needed only inside particlesystem ------------ */
 /* particle.c */
 void psys_disable_all(struct Object *ob);
index e7d96baea8e7fb685739db48b6ae07b1b06a3fa0..0d30fd70fa6dad60b5826312dd1957723d0eede6 100644 (file)
@@ -117,6 +117,13 @@ static void library_foreach_constraintObjectLooper(bConstraint *UNUSED(con), ID
        FOREACH_CALLBACK_INVOKE_ID_PP(data->self_id, id_pointer, data->flag, data->callback, data->user_data, IDWALK_NOP);
 }
 
+static void library_foreach_particlesystemsObjectLooper(
+        ParticleSystem *UNUSED(psys), ID **id_pointer, void *user_data, int cd_flag)
+{
+       LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
+       FOREACH_CALLBACK_INVOKE_ID_PP(data->self_id, id_pointer, data->flag, data->callback, data->user_data, cd_flag);
+}
+
 static void library_foreach_animationData(LibraryForeachIDData *data, AnimData *adt)
 {
        FCurve *fcu;
@@ -265,6 +272,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                case ID_OB:
                {
                        Object *object = (Object *) id;
+                       ParticleSystem *psys;
 
                        /* object data special case */
                        if (object->type == OB_EMPTY) {
@@ -326,6 +334,10 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
 
                        modifiers_foreachIDLink(object, library_foreach_modifiersForeachIDLink, &data);
                        BKE_constraints_id_loop(&object->constraints, library_foreach_constraintObjectLooper, &data);
+
+                       for (psys = object->particlesystem.first; psys; psys = psys->next) {
+                               BKE_particlesystem_id_loop(psys, library_foreach_particlesystemsObjectLooper, &data);
+                       }
                        break;
                }
 
index 9c720126ecaba82bfa5ec4e919df63eafe6873ad..a59a0b73b69ebdff351c86f903d8da8dcb4143ec 100644 (file)
@@ -77,6 +77,7 @@
 #include "BKE_cdderivedmesh.h"
 #include "BKE_collision.h"
 #include "BKE_effect.h"
+#include "BKE_library_query.h"
 #include "BKE_particle.h"
 #include "BKE_global.h"
 
@@ -4209,6 +4210,30 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
                invert_m4_m4(psys->imat, ob->obmat);
 }
 
+/* ID looper */
+
+void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata)
+{
+       ParticleTarget *pt;
+
+       func(psys, (ID **)&psys->part, userdata, IDWALK_NOP);
+       func(psys, (ID **)&psys->target_ob, userdata, IDWALK_NOP);
+       func(psys, (ID **)&psys->parent, userdata, IDWALK_NOP);
+
+       for (pt = psys->targets.first; pt; pt = pt->next) {
+               func(psys, (ID **)&pt->ob, userdata, IDWALK_NOP);
+       }
+
+       if (psys->part->phystype == PART_PHYS_BOIDS) {
+               ParticleData *pa;
+               int p;
+
+               for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++) {
+                       func(psys, (ID **)&pa->boid->ground, userdata, IDWALK_NOP);
+               }
+       }
+}
+
 /* **** Depsgraph evaluation **** */
 
 void BKE_particle_system_eval(EvaluationContext *UNUSED(eval_ctx),