Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/particle.c')
-rw-r--r--source/blender/blenkernel/intern/particle.c84
1 files changed, 55 insertions, 29 deletions
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index eb485e1522f..a003daf1042 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -283,8 +283,8 @@ int count_particles_mod(ParticleSystem *psys, int totgr, int cur)
}
return tot;
}
-/* we allocate path cache memory in chunks instead of a big contiguous
- * chunk, windows' memory allocater fails to find big blocks of memory often */
+/* We allocate path cache memory in chunks instead of a big contiguous
+ * chunk, windows' memory allocator fails to find big blocks of memory often. */
#define PATH_CACHE_BUF_SIZE 1024
@@ -410,7 +410,7 @@ struct LatticeDeformData *psys_create_lattice_deform_data(ParticleSimulationData
}
}
if (lattice) {
- lattice_deform_data = init_latt_deform(lattice, NULL);
+ lattice_deform_data = BKE_lattice_deform_data_create(lattice, NULL);
}
}
@@ -1297,7 +1297,7 @@ static void do_particle_interpolation(ParticleSystem *psys,
dfra = keys[2].time - keys[1].time;
keytime = (real_t - keys[1].time) / dfra;
- /* convert velocity to timestep size */
+ /* Convert velocity to time-step size. */
if (pind->keyed || pind->cache || point_vel) {
invdt = dfra * 0.04f * (psys ? psys->part->timetweak : 1.f);
mul_v3_fl(keys[1].vel, invdt);
@@ -1305,8 +1305,8 @@ static void do_particle_interpolation(ParticleSystem *psys,
interp_qt_qtqt(result->rot, keys[1].rot, keys[2].rot, keytime);
}
- /* Now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between
- * [0, 1]->[k2, k3] (k1 & k4 used for cardinal & bspline interpolation). */
+ /* Now we should have in chronological order k1<=k2<=t<=k3<=k4 with key-time between
+ * [0, 1]->[k2, k3] (k1 & k4 used for cardinal & b-spline interpolation). */
psys_interpolate_particle((pind->keyed || pind->cache || point_vel) ?
-1 /* signal for cubic interpolation */
:
@@ -2262,6 +2262,7 @@ static void do_path_effectors(ParticleSimulationData *sim,
sim->psys->part->effector_weights,
&epoint,
force,
+ NULL,
NULL);
mul_v3_fl(force,
@@ -3150,7 +3151,8 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
/* lattices have to be calculated separately to avoid mixups between effector calculations */
if (psys->lattice_deform_data) {
for (k = 0, ca = cache[p]; k <= segments; k++, ca++) {
- calc_latt_deform(psys->lattice_deform_data, ca->co, psys->lattice_strength);
+ BKE_lattice_deform_data_eval_co(
+ psys->lattice_deform_data, ca->co, psys->lattice_strength);
}
}
}
@@ -3185,7 +3187,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
psys->totcached = totpart;
if (psys->lattice_deform_data) {
- end_latt_deform(psys->lattice_deform_data);
+ BKE_lattice_deform_data_destroy(psys->lattice_deform_data);
psys->lattice_deform_data = NULL;
}
@@ -3609,7 +3611,8 @@ void psys_mat_hair_to_global(
/************************************************/
/* ParticleSettings handling */
/************************************************/
-ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob, const char *name)
+static ModifierData *object_add_or_copy_particle_system(
+ Main *bmain, Scene *scene, Object *ob, const char *name, const ParticleSystem *psys_orig)
{
ParticleSystem *psys;
ModifierData *md;
@@ -3620,7 +3623,7 @@ ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob,
}
if (name == NULL) {
- name = DATA_("ParticleSettings");
+ name = (psys_orig != NULL) ? psys_orig->name : DATA_("ParticleSettings");
}
psys = ob->particlesystem.first;
@@ -3633,8 +3636,13 @@ ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob,
BLI_addtail(&ob->particlesystem, psys);
psys_unique_name(ob, psys, name);
- psys->part = BKE_particlesettings_add(bmain, psys->name);
-
+ if (psys_orig != NULL) {
+ psys->part = psys_orig->part;
+ id_us_plus(&psys->part->id);
+ }
+ else {
+ psys->part = BKE_particlesettings_add(bmain, psys->name);
+ }
md = BKE_modifier_new(eModifierType_ParticleSystem);
BLI_strncpy(md->name, psys->name, sizeof(md->name));
BKE_modifier_unique_name(&ob->modifiers, md);
@@ -3654,6 +3662,20 @@ ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob,
return md;
}
+
+ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob, const char *name)
+{
+ return object_add_or_copy_particle_system(bmain, scene, ob, name, NULL);
+}
+
+ModifierData *object_copy_particle_system(Main *bmain,
+ Scene *scene,
+ Object *ob,
+ const ParticleSystem *psys_orig)
+{
+ return object_add_or_copy_particle_system(bmain, scene, ob, NULL, psys_orig);
+}
+
void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob)
{
ParticleSystem *psys = psys_get_current(ob);
@@ -3666,43 +3688,43 @@ void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob
/* Clear particle system in fluid modifier. */
if ((md = BKE_modifiers_findby_type(ob, eModifierType_Fluid))) {
- FluidModifierData *mmd = (FluidModifierData *)md;
+ FluidModifierData *fmd = (FluidModifierData *)md;
/* Clear particle system pointer in flow settings. */
- if ((mmd->type == MOD_FLUID_TYPE_FLOW) && mmd->flow && mmd->flow->psys) {
- if (mmd->flow->psys == psys) {
- mmd->flow->psys = NULL;
+ if ((fmd->type == MOD_FLUID_TYPE_FLOW) && fmd->flow && fmd->flow->psys) {
+ if (fmd->flow->psys == psys) {
+ fmd->flow->psys = NULL;
}
}
/* Clear particle flag in domain settings when removing particle system manually. */
- if (mmd->type == MOD_FLUID_TYPE_DOMAIN) {
+ if (fmd->type == MOD_FLUID_TYPE_DOMAIN) {
if (psys->part->type == PART_FLUID_FLIP) {
- mmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_FLIP;
+ fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_FLIP;
}
if (psys->part->type == PART_FLUID_SPRAY || psys->part->type == PART_FLUID_SPRAYFOAM ||
psys->part->type == PART_FLUID_SPRAYBUBBLE ||
psys->part->type == PART_FLUID_SPRAYFOAMBUBBLE) {
- mmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_SPRAY;
+ fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_SPRAY;
}
if (psys->part->type == PART_FLUID_FOAM || psys->part->type == PART_FLUID_SPRAYFOAM ||
psys->part->type == PART_FLUID_FOAMBUBBLE ||
psys->part->type == PART_FLUID_SPRAYFOAMBUBBLE) {
- mmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_FOAM;
+ fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_FOAM;
}
if (psys->part->type == PART_FLUID_BUBBLE || psys->part->type == PART_FLUID_FOAMBUBBLE ||
psys->part->type == PART_FLUID_SPRAYBUBBLE ||
psys->part->type == PART_FLUID_SPRAYFOAMBUBBLE) {
- mmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_BUBBLE;
+ fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_BUBBLE;
}
if (psys->part->type == PART_FLUID_TRACER) {
- mmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_TRACER;
+ fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_TRACER;
}
/* Disable combined export if combined particle system was deleted. */
if (psys->part->type == PART_FLUID_SPRAYFOAM || psys->part->type == PART_FLUID_SPRAYBUBBLE ||
psys->part->type == PART_FLUID_FOAMBUBBLE ||
psys->part->type == PART_FLUID_SPRAYFOAMBUBBLE) {
- mmd->domain->sndparticle_combined_export = SNDPARTICLE_COMBINED_EXPORT_OFF;
+ fmd->domain->sndparticle_combined_export = SNDPARTICLE_COMBINED_EXPORT_OFF;
}
}
}
@@ -4413,7 +4435,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
}
if (psys->lattice_deform_data && edit == 0) {
- calc_latt_deform(psys->lattice_deform_data, state->co, psys->lattice_strength);
+ BKE_lattice_deform_data_eval_co(
+ psys->lattice_deform_data, state->co, psys->lattice_strength);
}
}
}
@@ -4696,7 +4719,8 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
do_child_modifiers(&modifier_ctx, mat, state, t);
if (psys->lattice_deform_data) {
- calc_latt_deform(psys->lattice_deform_data, state->co, psys->lattice_strength);
+ BKE_lattice_deform_data_eval_co(
+ psys->lattice_deform_data, state->co, psys->lattice_strength);
}
}
else {
@@ -4760,7 +4784,8 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
}
if (sim->psys->lattice_deform_data) {
- calc_latt_deform(sim->psys->lattice_deform_data, state->co, psys->lattice_strength);
+ BKE_lattice_deform_data_eval_co(
+ sim->psys->lattice_deform_data, state->co, psys->lattice_strength);
}
}
@@ -4782,7 +4807,7 @@ void psys_get_dupli_texture(ParticleSystem *psys,
int num;
/* XXX: on checking '(psmd->dm != NULL)'
- * This is incorrect but needed for metaball evaluation.
+ * This is incorrect but needed for meta-ball evaluation.
* Ideally this would be calculated via the depsgraph, however with meta-balls,
* the entire scenes dupli's are scanned, which also looks into uncalculated data.
*
@@ -4970,12 +4995,13 @@ void psys_apply_hair_lattice(Depsgraph *depsgraph, Scene *scene, Object *ob, Par
hkey = pa->hair;
for (h = 0; h < pa->totkey; h++, hkey++) {
mul_m4_v3(hairmat, hkey->co);
- calc_latt_deform(psys->lattice_deform_data, hkey->co, psys->lattice_strength);
+ BKE_lattice_deform_data_eval_co(
+ psys->lattice_deform_data, hkey->co, psys->lattice_strength);
mul_m4_v3(imat, hkey->co);
}
}
- end_latt_deform(psys->lattice_deform_data);
+ BKE_lattice_deform_data_destroy(psys->lattice_deform_data);
psys->lattice_deform_data = NULL;
/* protect the applied shape */