forked from bartvdbraak/blender
Fix #35407: different particle behavior compared to 2.66, reverted part of 56073.
This commit is contained in:
parent
76ee6d3fc5
commit
0abe993435
@ -61,7 +61,6 @@ struct SurfaceModifierData;
|
||||
struct BVHTreeRay;
|
||||
struct BVHTreeRayHit;
|
||||
struct EdgeHash;
|
||||
struct RNG;
|
||||
|
||||
#define PARTICLE_P ParticleData * pa; int p
|
||||
#define LOOP_PARTICLES for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++)
|
||||
@ -83,7 +82,6 @@ typedef struct ParticleSimulationData {
|
||||
struct ParticleSystem *psys;
|
||||
struct ParticleSystemModifierData *psmd;
|
||||
struct ListBase *colliders;
|
||||
struct RNG *rng;
|
||||
/* Courant number. This is used to implement an adaptive time step. Only the
|
||||
* maximum value per time step is important. Only sph_integrate makes use of
|
||||
* this at the moment. Other solvers could, too. */
|
||||
|
@ -1263,7 +1263,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
|
||||
ChildParticle *cpa = NULL;
|
||||
ParticleKey state;
|
||||
ParticleCacheKey *cache;
|
||||
RNG *rng = NULL;
|
||||
float ctime, pa_time, scale = 1.0f;
|
||||
float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size = 0.0;
|
||||
float (*obmat)[4], (*oldobmat)[4];
|
||||
@ -1294,9 +1293,14 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
|
||||
totpart = psys->totpart;
|
||||
totchild = psys->totchild;
|
||||
|
||||
BLI_srandom(31415926 + psys->seed);
|
||||
|
||||
if ((psys->renderdata || part->draw_as == PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
|
||||
ParticleSimulationData sim = {NULL};
|
||||
|
||||
sim.scene = scene;
|
||||
sim.ob = par;
|
||||
sim.psys = psys;
|
||||
sim.psmd = psys_get_modifier(par, psys);
|
||||
/* make sure emitter imat is in global coordinates instead of render view coordinates */
|
||||
invert_m4_m4(par->imat, par->obmat);
|
||||
|
||||
@ -1328,12 +1332,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
|
||||
|
||||
psys_check_group_weights(part);
|
||||
|
||||
sim.scene = scene;
|
||||
sim.ob = par;
|
||||
sim.psys = psys;
|
||||
sim.psmd = psys_get_modifier(par, psys);
|
||||
sim.rng = BLI_rng_new(0);
|
||||
|
||||
psys->lattice = psys_get_lattice(&sim);
|
||||
|
||||
/* gather list of objects or single object */
|
||||
@ -1380,8 +1378,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
|
||||
obcopy = *ob;
|
||||
}
|
||||
|
||||
rng = BLI_rng_new_srandom(31415926 + psys->seed);
|
||||
|
||||
if (totchild == 0 || part->draw & PART_DRAW_PARENT)
|
||||
a = 0;
|
||||
else
|
||||
@ -1421,7 +1417,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
|
||||
|
||||
/* for groups, pick the object based on settings */
|
||||
if (part->draw & PART_DRAW_RAND_GR)
|
||||
b = BLI_rng_get_int(rng) % totgroup;
|
||||
b = BLI_rand() % totgroup;
|
||||
else
|
||||
b = a % totgroup;
|
||||
|
||||
@ -1565,8 +1561,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
|
||||
}
|
||||
else
|
||||
*ob = obcopy;
|
||||
|
||||
BLI_rng_free(sim.rng);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
@ -1579,9 +1573,6 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
|
||||
end_latt_deform(psys->lattice);
|
||||
psys->lattice = NULL;
|
||||
}
|
||||
|
||||
if (rng)
|
||||
BLI_rng_free(rng);
|
||||
}
|
||||
|
||||
static Object *find_family_object(Object **obar, char *family, char ch)
|
||||
|
@ -619,7 +619,6 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
|
||||
sim.scene= eff->scene;
|
||||
sim.ob= eff->ob;
|
||||
sim.psys= eff->psys;
|
||||
sim.rng= NULL;
|
||||
|
||||
/* TODO: time from actual previous calculated frame (step might not be 1) */
|
||||
state.time = cfra - 1.0f;
|
||||
|
@ -264,12 +264,11 @@ static void psys_create_frand(ParticleSystem *psys)
|
||||
{
|
||||
int i;
|
||||
float *rand = psys->frand = MEM_callocN(PSYS_FRAND_COUNT * sizeof(float), "particle randoms");
|
||||
RNG *rng = BLI_rng_new_srandom(psys->seed);
|
||||
|
||||
BLI_srandom(psys->seed);
|
||||
|
||||
for (i = 0; i < 1024; i++, rand++)
|
||||
*rand = BLI_rng_get_float(rng);
|
||||
|
||||
BLI_rng_free(rng);
|
||||
*rand = BLI_frand();
|
||||
}
|
||||
int psys_check_enabled(Object *ob, ParticleSystem *psys)
|
||||
{
|
||||
@ -3303,11 +3302,8 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
|
||||
sim.ob = ob;
|
||||
sim.psys = psys;
|
||||
sim.psmd = psys_get_modifier(ob, psys);
|
||||
sim.rng = BLI_rng_new(0);
|
||||
|
||||
psys_cache_child_paths(&sim, cfra, 1);
|
||||
|
||||
BLI_rng_free(sim.rng);
|
||||
}
|
||||
|
||||
/* clear recalc flag if set here */
|
||||
@ -4664,7 +4660,6 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys)
|
||||
sim.ob = ob;
|
||||
sim.psys = psys;
|
||||
sim.psmd = psys_get_modifier(ob, psys);
|
||||
sim.rng = BLI_rng_new(0);
|
||||
|
||||
psys->lattice = psys_get_lattice(&sim);
|
||||
|
||||
@ -4692,6 +4687,4 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys)
|
||||
/* protect the applied shape */
|
||||
psys->flag |= PSYS_EDITED;
|
||||
}
|
||||
|
||||
BLI_rng_free(sim.rng);
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ void psys_calc_dmcache(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
|
||||
}
|
||||
}
|
||||
|
||||
static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *finaldm, ParticleSystem *psys, RNG *rng)
|
||||
static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *finaldm, ParticleSystem *psys)
|
||||
{
|
||||
ChildParticle *cpa = NULL;
|
||||
int i, p;
|
||||
@ -440,9 +440,9 @@ static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *fi
|
||||
|
||||
/* create even spherical distribution inside unit sphere */
|
||||
while (length>=1.0f) {
|
||||
cpa->fuv[0]=2.0f*BLI_rng_get_float(rng)-1.0f;
|
||||
cpa->fuv[1]=2.0f*BLI_rng_get_float(rng)-1.0f;
|
||||
cpa->fuv[2]=2.0f*BLI_rng_get_float(rng)-1.0f;
|
||||
cpa->fuv[0]=2.0f*BLI_frand()-1.0f;
|
||||
cpa->fuv[1]=2.0f*BLI_frand()-1.0f;
|
||||
cpa->fuv[2]=2.0f*BLI_frand()-1.0f;
|
||||
length=len_v3(cpa->fuv);
|
||||
}
|
||||
|
||||
@ -872,7 +872,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch
|
||||
pa->foffset *= ctx->jit[p % (2 * ctx->jitlevel)];
|
||||
break;
|
||||
case PART_DISTR_RAND:
|
||||
pa->foffset *= BLI_rng_get_float(ctx->sim.rng);
|
||||
pa->foffset *= BLI_frand();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1065,15 +1065,15 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D
|
||||
if (from == PART_FROM_CHILD) {
|
||||
/* Simple children */
|
||||
if (part->childtype != PART_CHILD_FACES) {
|
||||
BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed + psys->child_seed);
|
||||
distribute_simple_children(scene, ob, finaldm, psys, ctx->sim.rng);
|
||||
BLI_srandom(31415926 + psys->seed + psys->child_seed);
|
||||
distribute_simple_children(scene, ob, finaldm, psys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Grid distribution */
|
||||
if (part->distr==PART_DISTR_GRID && from != PART_FROM_VERT) {
|
||||
BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed);
|
||||
BLI_srandom(31415926 + psys->seed);
|
||||
dm= CDDM_from_mesh((Mesh*)ob->data, ob);
|
||||
DM_ensure_tessface(dm);
|
||||
distribute_grid(dm,psys);
|
||||
@ -1085,7 +1085,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D
|
||||
/* Create trees and original coordinates if needed */
|
||||
if (from == PART_FROM_CHILD) {
|
||||
distr=PART_DISTR_RAND;
|
||||
BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed + psys->child_seed);
|
||||
BLI_srandom(31415926 + psys->seed + psys->child_seed);
|
||||
dm= finaldm;
|
||||
|
||||
/* BMESH ONLY */
|
||||
@ -1108,7 +1108,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D
|
||||
}
|
||||
else {
|
||||
distr = part->distr;
|
||||
BLI_rng_srandom(ctx->sim.rng, 31415926 + psys->seed);
|
||||
BLI_srandom(31415926 + psys->seed);
|
||||
|
||||
dm= CDDM_from_mesh((Mesh*)ob->data, ob);
|
||||
|
||||
@ -1264,7 +1264,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D
|
||||
|
||||
for (p=0; p<totpart; p++) {
|
||||
/* In theory element_sum[totelem] should be 1.0, but due to float errors this is not necessarily always true, so scale pos accordingly. */
|
||||
pos= BLI_rng_get_float(ctx->sim.rng) * element_sum[totelem];
|
||||
pos= BLI_frand() * element_sum[totelem];
|
||||
particle_element[p] = distribute_binary_search(element_sum, totelem, pos);
|
||||
particle_element[p] = MIN2(totelem-1, particle_element[p]);
|
||||
jitter_offset[particle_element[p]] = pos;
|
||||
@ -2911,9 +2911,9 @@ static void basic_force_cb(void *efdata_v, ParticleKey *state, float *force, flo
|
||||
|
||||
/* brownian force */
|
||||
if (part->brownfac != 0.0f) {
|
||||
force[0] += (BLI_rng_get_float(sim->rng)-0.5f) * part->brownfac;
|
||||
force[1] += (BLI_rng_get_float(sim->rng)-0.5f) * part->brownfac;
|
||||
force[2] += (BLI_rng_get_float(sim->rng)-0.5f) * part->brownfac;
|
||||
force[0] += (BLI_frand()-0.5f) * part->brownfac;
|
||||
force[1] += (BLI_frand()-0.5f) * part->brownfac;
|
||||
force[2] += (BLI_frand()-0.5f) * part->brownfac;
|
||||
}
|
||||
|
||||
if (part->flag & PART_ROT_DYN && epoint.ave)
|
||||
@ -3492,7 +3492,7 @@ static int collision_detect(ParticleData *pa, ParticleCollision *col, BVHTreeRay
|
||||
|
||||
return hit->index >= 0;
|
||||
}
|
||||
static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, int kill, int dynamic_rotation, RNG *rng)
|
||||
static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, int kill, int dynamic_rotation)
|
||||
{
|
||||
ParticleCollisionElement *pce = &col->pce;
|
||||
PartDeflect *pd = col->hit->pd;
|
||||
@ -3501,7 +3501,7 @@ static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeR
|
||||
float f = col->f + x * (1.0f - col->f); /* time factor of collision between timestep */
|
||||
float dt1 = (f - col->f) * col->total_time; /* time since previous collision (in seconds) */
|
||||
float dt2 = (1.0f - f) * col->total_time; /* time left after collision (in seconds) */
|
||||
int through = (BLI_rng_get_float(rng) < pd->pdef_perm) ? 1 : 0; /* did particle pass through the collision surface? */
|
||||
int through = (BLI_frand() < pd->pdef_perm) ? 1 : 0; /* did particle pass through the collision surface? */
|
||||
|
||||
/* calculate exact collision location */
|
||||
interp_v3_v3v3(co, col->co1, col->co2, x);
|
||||
@ -3526,8 +3526,8 @@ static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeR
|
||||
float v0_tan[3];/* tangential component of v0 */
|
||||
float vc_tan[3];/* tangential component of collision surface velocity */
|
||||
float v0_dot, vc_dot;
|
||||
float damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_rng_get_float(rng) - 0.5f);
|
||||
float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_rng_get_float(rng) - 0.5f);
|
||||
float damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_frand() - 0.5f);
|
||||
float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_frand() - 0.5f);
|
||||
float distance, nor[3], dot;
|
||||
|
||||
CLAMP(damp,0.0f, 1.0f);
|
||||
@ -3735,7 +3735,7 @@ static void collision_check(ParticleSimulationData *sim, int p, float dfra, floa
|
||||
|
||||
if (collision_count == COLLISION_MAX_COLLISIONS)
|
||||
collision_fail(pa, &col);
|
||||
else if (collision_response(pa, &col, &hit, part->flag & PART_DIE_ON_COL, part->flag & PART_ROT_DYN, sim->rng)==0)
|
||||
else if (collision_response(pa, &col, &hit, part->flag & PART_DIE_ON_COL, part->flag & PART_ROT_DYN)==0)
|
||||
return;
|
||||
}
|
||||
else
|
||||
@ -4095,7 +4095,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
|
||||
{
|
||||
ParticleSystem *psys = sim->psys;
|
||||
ParticleSettings *part=psys->part;
|
||||
RNG *rng;
|
||||
BoidBrainData bbd;
|
||||
ParticleTexture ptex;
|
||||
PARTICLE_P;
|
||||
@ -4122,7 +4121,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
|
||||
return;
|
||||
}
|
||||
|
||||
rng = BLI_rng_new_srandom(31415926 + (int)cfra + psys->seed);
|
||||
BLI_srandom(31415926 + (int)cfra + psys->seed);
|
||||
|
||||
psys_update_effectors(sim);
|
||||
|
||||
@ -4139,7 +4138,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
|
||||
bbd.cfra = cfra;
|
||||
bbd.dfra = dfra;
|
||||
bbd.timestep = timestep;
|
||||
bbd.rng = rng;
|
||||
|
||||
psys_update_particle_tree(psys, cfra);
|
||||
|
||||
@ -4323,7 +4321,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
|
||||
}
|
||||
|
||||
free_collider_cache(&sim->colliders);
|
||||
BLI_rng_free(rng);
|
||||
}
|
||||
static void update_children(ParticleSimulationData *sim)
|
||||
{
|
||||
@ -4820,8 +4817,6 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
|
||||
if (!sim.psmd->dm)
|
||||
return;
|
||||
|
||||
sim.rng = BLI_rng_new(0);
|
||||
|
||||
if (part->from != PART_FROM_VERT) {
|
||||
DM_ensure_tessface(sim.psmd->dm);
|
||||
}
|
||||
@ -4962,7 +4957,5 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys)
|
||||
/* save matrix for duplicators, at rendertime the actual dupliobject's matrix is used so don't update! */
|
||||
if (psys->renderdata==0)
|
||||
invert_m4_m4(psys->imat, ob->obmat);
|
||||
|
||||
BLI_rng_free(sim.rng);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user