Particles now got that force-hiding feature, too --> jahka: please take a look :)
This commit is contained in:
@@ -66,7 +66,7 @@ void pdEndEffectors(struct ListBase *lb);
|
|||||||
void pdDoEffectors(struct ListBase *lb, float *opco, float *force, float *speed, float cur_time, float loc_time, unsigned int flags);
|
void pdDoEffectors(struct ListBase *lb, float *opco, float *force, float *speed, float cur_time, float loc_time, unsigned int flags);
|
||||||
|
|
||||||
/* required for particle_system.c */
|
/* required for particle_system.c */
|
||||||
void do_physical_effector(short type, float force_val, float distance, float falloff, float size, float damp, float *eff_velocity, float *vec_to_part, float *velocity, float *field, int planar, struct RNG *rng, float noise_factor);
|
void do_physical_effector(Object *ob, float *opco, short type, float force_val, float distance, float falloff, float size, float damp, float *eff_velocity, float *vec_to_part, float *velocity, float *field, int planar, struct RNG *rng, float noise_factor);
|
||||||
float effector_falloff(struct PartDeflect *pd, float *eff_velocity, float *vec_to_part);
|
float effector_falloff(struct PartDeflect *pd, float *eff_velocity, float *vec_to_part);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,60 @@ void pdEndEffectors(ListBase *lb)
|
|||||||
/* Effectors */
|
/* Effectors */
|
||||||
/************************************************/
|
/************************************************/
|
||||||
|
|
||||||
|
// triangle - ray callback function
|
||||||
|
static void eff_tri_ray_hit(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
|
||||||
|
{
|
||||||
|
// whenever we hit a bounding box, we don't check further
|
||||||
|
hit->dist = -1;
|
||||||
|
hit->index = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get visibility of a wind ray
|
||||||
|
static float eff_calc_visibility(Object *ob, float *co, float *dir)
|
||||||
|
{
|
||||||
|
CollisionModifierData **collobjs = NULL;
|
||||||
|
int numcollobj = 0, i;
|
||||||
|
float norm[3], len = 0.0;
|
||||||
|
float visibility = 1.0;
|
||||||
|
|
||||||
|
collobjs = get_collisionobjects(ob, &numcollobj);
|
||||||
|
|
||||||
|
if(!collobjs)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
VECCOPY(norm, dir);
|
||||||
|
VecMulf(norm, -1.0);
|
||||||
|
len = Normalize(norm);
|
||||||
|
|
||||||
|
// check all collision objects
|
||||||
|
for(i = 0; i < numcollobj; i++)
|
||||||
|
{
|
||||||
|
CollisionModifierData *collmd = collobjs[i];
|
||||||
|
|
||||||
|
if(collmd->bvhtree)
|
||||||
|
{
|
||||||
|
BVHTreeRayHit hit;
|
||||||
|
|
||||||
|
hit.index = -1;
|
||||||
|
hit.dist = len + FLT_EPSILON;
|
||||||
|
|
||||||
|
// check if the way is blocked
|
||||||
|
if(BLI_bvhtree_ray_cast(collmd->bvhtree, co, norm, &hit, eff_tri_ray_hit, NULL)>=0)
|
||||||
|
{
|
||||||
|
// visibility is only between 0 and 1, calculated from 1-absorption
|
||||||
|
visibility *= MAX2(0.0, MIN2(1.0, (1.0-((float)collmd->absorption)*0.01)));
|
||||||
|
|
||||||
|
if(visibility <= 0.0f)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_freeN(collobjs);
|
||||||
|
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
// noise function for wind e.g.
|
// noise function for wind e.g.
|
||||||
static float wind_func(struct RNG *rng, float strength)
|
static float wind_func(struct RNG *rng, float strength)
|
||||||
{
|
{
|
||||||
@@ -315,12 +369,18 @@ float effector_falloff(PartDeflect *pd, float *eff_velocity, float *vec_to_part)
|
|||||||
return falloff;
|
return falloff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_physical_effector(short type, float force_val, float distance, float falloff, float size, float damp, float *eff_velocity, float *vec_to_part, float *velocity, float *field, int planar, struct RNG *rng, float noise_factor)
|
void do_physical_effector(Object *ob, float *opco, short type, float force_val, float distance, float falloff, float size, float damp, float *eff_velocity, float *vec_to_part, float *velocity, float *field, int planar, struct RNG *rng, float noise_factor)
|
||||||
{
|
{
|
||||||
float mag_vec[3]={0,0,0};
|
float mag_vec[3]={0,0,0};
|
||||||
float temp[3], temp2[3];
|
float temp[3], temp2[3];
|
||||||
float eff_vel[3];
|
float eff_vel[3];
|
||||||
float noise = 0;
|
float noise = 0, visibility;
|
||||||
|
|
||||||
|
// calculate visibility
|
||||||
|
visibility = eff_calc_visibility(ob, opco, vec_to_part);
|
||||||
|
if(visibility <= 0.0)
|
||||||
|
return;
|
||||||
|
falloff *= visibility;
|
||||||
|
|
||||||
VecCopyf(eff_vel,eff_velocity);
|
VecCopyf(eff_vel,eff_velocity);
|
||||||
Normalize(eff_vel);
|
Normalize(eff_vel);
|
||||||
@@ -330,7 +390,7 @@ void do_physical_effector(short type, float force_val, float distance, float fal
|
|||||||
VECCOPY(mag_vec,eff_vel);
|
VECCOPY(mag_vec,eff_vel);
|
||||||
|
|
||||||
// add wind noise here, only if we have wind
|
// add wind noise here, only if we have wind
|
||||||
if((noise_factor> 0.0f) && (force_val > FLT_EPSILON))
|
if((noise_factor > 0.0f) && (force_val > FLT_EPSILON))
|
||||||
noise = wind_func(rng, noise_factor);
|
noise = wind_func(rng, noise_factor);
|
||||||
|
|
||||||
VecMulf(mag_vec,(force_val+noise)*falloff);
|
VecMulf(mag_vec,(force_val+noise)*falloff);
|
||||||
@@ -393,56 +453,6 @@ void do_physical_effector(short type, float force_val, float distance, float fal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void eff_tri_ray_hit(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
|
|
||||||
{
|
|
||||||
hit->dist = -1;
|
|
||||||
hit->index = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
float eff_calc_visibility(Object *ob, float *co, float *dir, float cur_time)
|
|
||||||
{
|
|
||||||
CollisionModifierData **collobjs = NULL;
|
|
||||||
int numcollobj = 0, i;
|
|
||||||
float norm[3], len = 0.0;
|
|
||||||
float visibility = 1.0;
|
|
||||||
|
|
||||||
collobjs = get_collisionobjects(ob, &numcollobj);
|
|
||||||
|
|
||||||
if(!collobjs)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
VECCOPY(norm, dir);
|
|
||||||
VecMulf(norm, -1.0);
|
|
||||||
len = Normalize(norm);
|
|
||||||
|
|
||||||
// check all collision objects
|
|
||||||
for(i = 0; i < numcollobj; i++)
|
|
||||||
{
|
|
||||||
CollisionModifierData *collmd = collobjs[i];
|
|
||||||
|
|
||||||
if(collmd->bvhtree)
|
|
||||||
{
|
|
||||||
BVHTreeRayHit hit;
|
|
||||||
|
|
||||||
hit.index = -1;
|
|
||||||
hit.dist = len + FLT_EPSILON;
|
|
||||||
|
|
||||||
|
|
||||||
// check if the way is blocked
|
|
||||||
if(BLI_bvhtree_ray_cast(collmd->bvhtree, co, norm, &hit, eff_tri_ray_hit, NULL)>=0)
|
|
||||||
{
|
|
||||||
visibility *= MAX2(0.0, MIN2(1.0, (1.0-((float)collmd->absorbation)*0.01)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MEM_freeN(collobjs);
|
|
||||||
|
|
||||||
return visibility;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -------- pdDoEffectors() --------
|
/* -------- pdDoEffectors() --------
|
||||||
generic force/speed system, now used for particles and softbodies
|
generic force/speed system, now used for particles and softbodies
|
||||||
lb = listbase with objects that take part in effecting
|
lb = listbase with objects that take part in effecting
|
||||||
@@ -478,7 +488,7 @@ void pdDoEffectors(ListBase *lb, float *opco, float *force, float *speed, float
|
|||||||
float *obloc;
|
float *obloc;
|
||||||
|
|
||||||
float distance, vec_to_part[3];
|
float distance, vec_to_part[3];
|
||||||
float falloff, visibility;
|
float falloff;
|
||||||
|
|
||||||
/* Cycle through collected objects, get total of (1/(gravity_strength * dist^gravity_power)) */
|
/* Cycle through collected objects, get total of (1/(gravity_strength * dist^gravity_power)) */
|
||||||
/* Check for min distance here? (yes would be cool to add that, ton) */
|
/* Check for min distance here? (yes would be cool to add that, ton) */
|
||||||
@@ -499,20 +509,15 @@ void pdDoEffectors(ListBase *lb, float *opco, float *force, float *speed, float
|
|||||||
VecSubf(vec_to_part, opco, ob->obmat[3]);
|
VecSubf(vec_to_part, opco, ob->obmat[3]);
|
||||||
distance = VecLength(vec_to_part);
|
distance = VecLength(vec_to_part);
|
||||||
|
|
||||||
falloff=effector_falloff(pd,ob->obmat[2],vec_to_part);
|
falloff=effector_falloff(pd,ob->obmat[2],vec_to_part);
|
||||||
|
|
||||||
if(falloff<=0.0f)
|
if(falloff<=0.0f)
|
||||||
continue;
|
|
||||||
|
|
||||||
visibility = eff_calc_visibility(ob, opco, vec_to_part, cur_time);
|
|
||||||
|
|
||||||
if((visibility*falloff)<=0.0f)
|
|
||||||
; /* don't do anything */
|
; /* don't do anything */
|
||||||
else {
|
else {
|
||||||
float field[3]={0,0,0}, tmp[3];
|
float field[3]={0,0,0}, tmp[3];
|
||||||
VECCOPY(field, force);
|
VECCOPY(field, force);
|
||||||
do_physical_effector(pd->forcefield,pd->f_strength,distance,
|
do_physical_effector(ob, opco, pd->forcefield,pd->f_strength,distance,
|
||||||
visibility*falloff,pd->f_dist,pd->f_damp,ob->obmat[2],vec_to_part,
|
falloff,pd->f_dist,pd->f_damp,ob->obmat[2],vec_to_part,
|
||||||
speed,force,pd->flag&PFIELD_PLANAR, pd->rng, pd->f_noise);
|
speed,force,pd->flag&PFIELD_PLANAR, pd->rng, pd->f_noise);
|
||||||
|
|
||||||
// for softbody backward compatibility
|
// for softbody backward compatibility
|
||||||
|
|||||||
@@ -1405,7 +1405,6 @@ void cloth_calc_force(ClothModifierData *clmd, lfVector *lF, lfVector *lX, lfVec
|
|||||||
unsigned int numverts = cloth->numverts;
|
unsigned int numverts = cloth->numverts;
|
||||||
LinkNode *search = cloth->springs;
|
LinkNode *search = cloth->springs;
|
||||||
lfVector *winvec;
|
lfVector *winvec;
|
||||||
ClothVertex *verts = cloth->verts;
|
|
||||||
|
|
||||||
VECCOPY(gravity, clmd->sim_parms->gravity);
|
VECCOPY(gravity, clmd->sim_parms->gravity);
|
||||||
mul_fvector_S(gravity, gravity, 0.001f); /* scale gravity force */
|
mul_fvector_S(gravity, gravity, 0.001f); /* scale gravity force */
|
||||||
|
|||||||
@@ -2616,7 +2616,7 @@ void do_effectors(int pa_no, ParticleData *pa, ParticleKey *state, Object *ob, P
|
|||||||
pd->flag & PFIELD_TEX_OBJECT, (pd->flag & PFIELD_TEX_ROOTCO) ? rootco : state->co, eob->obmat,
|
pd->flag & PFIELD_TEX_OBJECT, (pd->flag & PFIELD_TEX_ROOTCO) ? rootco : state->co, eob->obmat,
|
||||||
pd->f_strength, falloff, force_field);
|
pd->f_strength, falloff, force_field);
|
||||||
} else {
|
} else {
|
||||||
do_physical_effector(pd->forcefield,pd->f_strength,distance,
|
do_physical_effector(eob, state->co, pd->forcefield,pd->f_strength,distance,
|
||||||
falloff,pd->f_dist,pd->f_damp,eob->obmat[2],vec_to_part,
|
falloff,pd->f_dist,pd->f_damp,eob->obmat[2],vec_to_part,
|
||||||
pa->state.vel,force_field,pd->flag&PFIELD_PLANAR, pd->rng, pd->f_noise);
|
pa->state.vel,force_field,pd->flag&PFIELD_PLANAR, pd->rng, pd->f_noise);
|
||||||
}
|
}
|
||||||
@@ -2665,7 +2665,7 @@ void do_effectors(int pa_no, ParticleData *pa, ParticleKey *state, Object *ob, P
|
|||||||
if(falloff<=0.0f)
|
if(falloff<=0.0f)
|
||||||
; /* don't do anything */
|
; /* don't do anything */
|
||||||
else
|
else
|
||||||
do_physical_effector(pd->forcefield,pd->f_strength,distance,
|
do_physical_effector(eob, state->co, pd->forcefield,pd->f_strength,distance,
|
||||||
falloff,epart->size,pd->f_damp,estate.vel,vec_to_part,
|
falloff,epart->size,pd->f_damp,estate.vel,vec_to_part,
|
||||||
state->vel,force_field,0, pd->rng, pd->f_noise);
|
state->vel,force_field,0, pd->rng, pd->f_noise);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -390,7 +390,7 @@ typedef struct CollisionModifierData {
|
|||||||
|
|
||||||
unsigned int numverts;
|
unsigned int numverts;
|
||||||
unsigned int numfaces;
|
unsigned int numfaces;
|
||||||
short absorbation; /* used for forces, in % */
|
short absorption; /* used for forces, in % */
|
||||||
short pad;
|
short pad;
|
||||||
float time; /* cfra time of modifier */
|
float time; /* cfra time of modifier */
|
||||||
struct BVHTree *bvhtree; /* bounding volume hierarchy for this cloth object */
|
struct BVHTree *bvhtree; /* bounding volume hierarchy for this cloth object */
|
||||||
|
|||||||
@@ -3306,7 +3306,7 @@ static void object_panel_collision(Object *ob)
|
|||||||
// collision options
|
// collision options
|
||||||
if(collmd)
|
if(collmd)
|
||||||
{
|
{
|
||||||
uiDefButS(block, NUM, B_FIELD_CHANGE, "Absoption: ", 10,0,150,20, &collmd->absorbation, 0.0, 100, 1, 2, "How much of effector force gets lost during collision with this object (in percent).");
|
uiDefButS(block, NUM, B_FIELD_CHANGE, "Absorption: ", 10,0,150,20, &collmd->absorption, 0.0, 100, 1, 2, "How much of effector force gets lost during collision with this object (in percent).");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user