Draw manager: Make particle code drawing closer to old viewport
The way how particle state is to be accessed or used did not change in Blender 2.8, so the drawing code should follow old design. This code is somewhat duplicated from drawobject.c, but old draw code is on the way to be removed anyway. This fixes issue with disappearing particles when tweaking number of particles.
This commit is contained in:
@@ -2573,9 +2573,9 @@ Gwn_Batch *DRW_cache_particles_get_hair(ParticleSystem *psys, ModifierData *md)
|
||||
return DRW_particles_batch_cache_get_hair(psys, md);
|
||||
}
|
||||
|
||||
Gwn_Batch *DRW_cache_particles_get_dots(ParticleSystem *psys)
|
||||
Gwn_Batch *DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
|
||||
{
|
||||
return DRW_particles_batch_cache_get_dots(psys);
|
||||
return DRW_particles_batch_cache_get_dots(object, psys);
|
||||
}
|
||||
|
||||
Gwn_Batch *DRW_cache_particles_get_prim(int type)
|
||||
|
||||
@@ -165,7 +165,7 @@ struct Gwn_Batch *DRW_cache_lattice_vert_overlay_get(struct Object *ob);
|
||||
|
||||
/* Particles */
|
||||
struct Gwn_Batch *DRW_cache_particles_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
|
||||
struct Gwn_Batch *DRW_cache_particles_get_dots(struct ParticleSystem *psys);
|
||||
struct Gwn_Batch *DRW_cache_particles_get_dots(struct Object *object, struct ParticleSystem *psys);
|
||||
struct Gwn_Batch *DRW_cache_particles_get_prim(int type);
|
||||
|
||||
/* Metaball */
|
||||
|
||||
@@ -122,6 +122,6 @@ void DRW_mesh_cache_sculpt_coords_ensure(struct Mesh *me);
|
||||
|
||||
/* Particles */
|
||||
struct Gwn_Batch *DRW_particles_batch_cache_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
|
||||
struct Gwn_Batch *DRW_particles_batch_cache_get_dots(struct ParticleSystem *psys);
|
||||
struct Gwn_Batch *DRW_particles_batch_cache_get_dots(struct Object *object, struct ParticleSystem *psys);
|
||||
|
||||
#endif /* __DRAW_CACHE_IMPL_H__ */
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
* \brief Particle API for render engines
|
||||
*/
|
||||
|
||||
#include "DRW_render.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
@@ -442,7 +444,7 @@ static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys, Modifi
|
||||
cache->segments = GWN_indexbuf_build(&elb);
|
||||
}
|
||||
|
||||
static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchCache *cache)
|
||||
static void particle_batch_cache_ensure_pos(Object *object, ParticleSystem *psys, ParticleBatchCache *cache)
|
||||
{
|
||||
if (cache->pos != NULL) {
|
||||
return;
|
||||
@@ -452,6 +454,23 @@ static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchC
|
||||
static unsigned pos_id, rot_id, val_id;
|
||||
int i, curr_point;
|
||||
ParticleData *pa;
|
||||
ParticleKey state;
|
||||
ParticleSimulationData sim = {NULL};
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
|
||||
sim.eval_ctx = &draw_ctx->eval_ctx;
|
||||
sim.scene = draw_ctx->scene;
|
||||
sim.ob = object;
|
||||
sim.psys = psys;
|
||||
sim.psmd = psys_get_modifier(object, psys);
|
||||
|
||||
if (psys->part->phystype == PART_PHYS_KEYED) {
|
||||
if (psys->flag & PSYS_KEYED) {
|
||||
psys_count_keyed_targets(&sim);
|
||||
if (psys->totkeyed == 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GWN_VERTBUF_DISCARD_SAFE(cache->pos);
|
||||
GWN_INDEXBUF_DISCARD_SAFE(cache->segments);
|
||||
@@ -467,30 +486,31 @@ static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchC
|
||||
GWN_vertbuf_data_alloc(cache->pos, psys->totpart);
|
||||
|
||||
for (curr_point = 0, i = 0, pa = psys->particles; i < psys->totpart; i++, pa++) {
|
||||
if (pa->state.time >= pa->time && pa->state.time < pa->dietime &&
|
||||
!(pa->flag & (PARS_NO_DISP | PARS_UNEXIST)))
|
||||
{
|
||||
float val;
|
||||
|
||||
GWN_vertbuf_attr_set(cache->pos, pos_id, curr_point, pa->state.co);
|
||||
GWN_vertbuf_attr_set(cache->pos, rot_id, curr_point, pa->state.rot);
|
||||
|
||||
switch (psys->part->draw_col) {
|
||||
case PART_DRAW_COL_VEL:
|
||||
val = len_v3(pa->state.vel) / psys->part->color_vec_max;
|
||||
break;
|
||||
case PART_DRAW_COL_ACC:
|
||||
val = len_v3v3(pa->state.vel, pa->prev_state.vel) / ((pa->state.time - pa->prev_state.time) * psys->part->color_vec_max);
|
||||
break;
|
||||
default:
|
||||
val = -1.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
GWN_vertbuf_attr_set(cache->pos, val_id, curr_point, &val);
|
||||
|
||||
curr_point++;
|
||||
state.time = draw_ctx->eval_ctx.ctime;
|
||||
if (!psys_get_particle_state(&sim, curr_point, &state, 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float val;
|
||||
|
||||
GWN_vertbuf_attr_set(cache->pos, pos_id, curr_point, pa->state.co);
|
||||
GWN_vertbuf_attr_set(cache->pos, rot_id, curr_point, pa->state.rot);
|
||||
|
||||
switch (psys->part->draw_col) {
|
||||
case PART_DRAW_COL_VEL:
|
||||
val = len_v3(pa->state.vel) / psys->part->color_vec_max;
|
||||
break;
|
||||
case PART_DRAW_COL_ACC:
|
||||
val = len_v3v3(pa->state.vel, pa->prev_state.vel) / ((pa->state.time - pa->prev_state.time) * psys->part->color_vec_max);
|
||||
break;
|
||||
default:
|
||||
val = -1.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
GWN_vertbuf_attr_set(cache->pos, val_id, curr_point, &val);
|
||||
|
||||
curr_point++;
|
||||
}
|
||||
|
||||
if (curr_point != psys->totpart) {
|
||||
@@ -511,12 +531,12 @@ Gwn_Batch *DRW_particles_batch_cache_get_hair(ParticleSystem *psys, ModifierData
|
||||
return cache->hairs;
|
||||
}
|
||||
|
||||
Gwn_Batch *DRW_particles_batch_cache_get_dots(ParticleSystem *psys)
|
||||
Gwn_Batch *DRW_particles_batch_cache_get_dots(Object *object, ParticleSystem *psys)
|
||||
{
|
||||
ParticleBatchCache *cache = particle_batch_cache_get(psys);
|
||||
|
||||
if (cache->hairs == NULL) {
|
||||
particle_batch_cache_ensure_pos(psys, cache);
|
||||
particle_batch_cache_ensure_pos(object, psys, cache);
|
||||
cache->hairs = GWN_batch_create(GWN_PRIM_POINTS, cache->pos, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -1812,7 +1812,7 @@ static void OBJECT_cache_populate_particles(Object *ob,
|
||||
unit_m4(mat);
|
||||
|
||||
if (draw_as != PART_DRAW_PATH) {
|
||||
struct Gwn_Batch *geom = DRW_cache_particles_get_dots(psys);
|
||||
struct Gwn_Batch *geom = DRW_cache_particles_get_dots(ob, psys);
|
||||
DRWShadingGroup *shgrp = NULL;
|
||||
static int screen_space[2] = {0, 1};
|
||||
static float def_prim_col[3] = {0.5f, 0.5f, 0.5f};
|
||||
|
||||
Reference in New Issue
Block a user