Fix #36394: rendering a point density texture with a hair particle system did

not work correct, the positions would change over time and child particles did
not render.
This commit is contained in:
Brecht Van Lommel 2013-08-08 15:36:03 +00:00
parent a6c4c6dbc6
commit af807bd24d

@ -107,6 +107,7 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
{
DerivedMesh* dm;
ParticleKey state;
ParticleCacheKey *cache;
ParticleSimulationData sim= {NULL};
ParticleData *pa=NULL;
float cfra = BKE_scene_frame_get(re->scene);
@ -153,44 +154,62 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
for (i=0, pa=psys->particles; i < total_particles; i++, pa++) {
state.time = cfra;
if (psys_get_particle_state(&sim, i, &state, 0)) {
copy_v3_v3(partco, state.co);
if (pd->psys_cache_space == TEX_PD_OBJECTSPACE)
mul_m4_v3(ob->imat, partco);
else if (pd->psys_cache_space == TEX_PD_OBJECTLOC) {
sub_v3_v3(partco, ob->loc);
}
else {
/* TEX_PD_WORLDSPACE */
}
BLI_bvhtree_insert(pd->point_tree, i, partco, 1);
if (data_used & POINT_DATA_VEL) {
pd->point_data[i*3 + 0] = state.vel[0];
pd->point_data[i*3 + 1] = state.vel[1];
pd->point_data[i*3 + 2] = state.vel[2];
}
if (psys->part->type == PART_HAIR) {
/* hair particles */
if (i < psys->totpart && psys->pathcache)
cache = psys->pathcache[i];
else if (i >= psys->totpart && psys->childcache)
cache = psys->childcache[i - psys->totpart];
else
continue;
cache += cache->steps; /* use endpoint */
copy_v3_v3(state.co, cache->co);
zero_v3(state.vel);
state.time = 0.0f;
}
else {
/* emitter particles */
state.time = cfra;
if (!psys_get_particle_state(&sim, i, &state, 0))
continue;
if (data_used & POINT_DATA_LIFE) {
float pa_time;
if (i < psys->totpart) {
pa_time = (cfra - pa->time)/pa->lifetime;
state.time = (cfra - pa->time)/pa->lifetime;
}
else {
ChildParticle *cpa= (psys->child + i) - psys->totpart;
float pa_birthtime, pa_dietime;
pa_time = psys_get_child_time(psys, cpa, cfra, &pa_birthtime, &pa_dietime);
state.time = psys_get_child_time(psys, cpa, cfra, &pa_birthtime, &pa_dietime);
}
pd->point_data[offset + i] = pa_time;
}
}
copy_v3_v3(partco, state.co);
if (pd->psys_cache_space == TEX_PD_OBJECTSPACE)
mul_m4_v3(ob->imat, partco);
else if (pd->psys_cache_space == TEX_PD_OBJECTLOC) {
sub_v3_v3(partco, ob->loc);
}
else {
/* TEX_PD_WORLDSPACE */
}
BLI_bvhtree_insert(pd->point_tree, i, partco, 1);
if (data_used & POINT_DATA_VEL) {
pd->point_data[i*3 + 0] = state.vel[0];
pd->point_data[i*3 + 1] = state.vel[1];
pd->point_data[i*3 + 2] = state.vel[2];
}
if (data_used & POINT_DATA_LIFE) {
pd->point_data[offset + i] = state.time;
}
}
BLI_bvhtree_balance(pd->point_tree);