Particles: Add utility function to copy particles from one system to another
This commit is contained in:
parent
92c519ff17
commit
aa3f0b0998
|
@ -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]);
|
||||
|
|
|
@ -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 */
|
||||
/************************************************/
|
||||
|
|
Loading…
Reference in New Issue