Commit: aa3f0b0998613d50f423dd4347f4c80e91d05528
Author: Sergey Sharybin
Date:   Tue Jun 19 11:40:09 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBaa3f0b0998613d50f423dd4347f4c80e91d05528

Particles: Add utility function to copy particles from one system to another

===================================================================

M       source/blender/blenkernel/BKE_particle.h
M       source/blender/blenkernel/intern/particle.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_particle.h 
b/source/blender/blenkernel/BKE_particle.h
index 64cf7e8402e..11aa67d7f25 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -318,6 +318,9 @@ void BKE_particlesettings_free(struct ParticleSettings 
*part);
 void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit 
*edit);
 void psys_free(struct Object *ob, struct ParticleSystem *psys);
 
+/* Copy. */
+void psys_copy_particles(struct ParticleSystem *psys_dst, struct 
ParticleSystem *psys_src);
+
 bool psys_render_simplify_params(struct ParticleSystem *psys, struct 
ChildParticle *cpa, float *params);
 
 void psys_interpolate_uvs(const struct MTFace *tface, int quad, const float 
w[4], float uvco[2]);
diff --git a/source/blender/blenkernel/intern/particle.c 
b/source/blender/blenkernel/intern/particle.c
index 41445492c04..9461b0a21a5 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -653,6 +653,51 @@ void psys_free(Object *ob, ParticleSystem *psys)
        }
 }
 
+void psys_copy_particles(ParticleSystem *psys_dst, ParticleSystem *psys_src)
+{
+       /* Free existing particles. */
+       if (psys_dst->particles != psys_src->particles) {
+               psys_free_particles(psys_dst);
+       }
+       if (psys_dst->child != psys_src->child) {
+               psys_free_children(psys_dst);
+       }
+       /* Restore counters. */
+       psys_dst->totpart = psys_src->totpart;
+       psys_dst->totchild = psys_src->totchild;
+       /* Copy particles and children. */
+       psys_dst->particles = MEM_dupallocN(psys_src->particles);
+       psys_dst->child = MEM_dupallocN(psys_src->child);
+       if (psys_dst->part->type == PART_HAIR) {
+               ParticleData *pa;
+               int p;
+               for (p = 0, pa = psys_dst->particles; p < psys_dst->totpart; 
p++, pa++) {
+                       pa->hair = MEM_dupallocN(pa->hair);
+               }
+       }
+       if (psys_dst->particles && (psys_dst->particles->keys || 
psys_dst->particles->boid)) {
+               ParticleKey *key = psys_dst->particles->keys;
+               BoidParticle *boid = psys_dst->particles->boid;
+               ParticleData *pa;
+               int p;
+               if (key != NULL) {
+                       key = MEM_dupallocN(key);
+               }
+               if (boid != NULL) {
+                       boid = MEM_dupallocN(boid);
+               }
+               for (p = 0, pa = psys_dst->particles; p < psys_dst->totpart; 
p++, pa++) {
+                       if (boid != NULL) {
+                               pa->boid = boid++;
+                       }
+                       if (key != NULL) {
+                               pa->keys = key;
+                               key += pa->totkey;
+                       }
+               }
+       }
+}
+
 /************************************************/
 /*                     Interpolation                                           
*/
 /************************************************/

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to