[Bf-blender-cvs] [979c48fd66e] blender2.8: Particle edit: Decouple caches for regular and edit strands
Sergey Sharybin
noreply at git.blender.org
Tue May 15 17:21:29 CEST 2018
Commit: 979c48fd66e73d649fd674b349e40820773a7229
Author: Sergey Sharybin
Date: Tue May 15 11:39:14 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB979c48fd66e73d649fd674b349e40820773a7229
Particle edit: Decouple caches for regular and edit strands
Makes it possible to have children strands to be visible during combing.
Actual implementation still needs work though.
===================================================================
M source/blender/draw/intern/draw_cache_impl_particles.c
===================================================================
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index a73731bec2f..02aa03fa622 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -58,18 +58,31 @@ static void particle_batch_cache_clear(ParticleSystem *psys);
/* ---------------------------------------------------------------------- */
/* Particle Gwn_Batch Cache */
-typedef struct ParticleBatchCache {
- /* Object mode strands for hair and points for particle,
- * strands for paths when in edit mode.
- */
+typedef struct ParticlePointCache {
+ Gwn_VertBuf *pos;
+ Gwn_Batch *points;
+ int elems_count;
+ int point_count;
+} ParticlePointCache;
+
+typedef struct ParticleHairCache {
Gwn_VertBuf *pos;
Gwn_IndexBuf *indices;
Gwn_Batch *hairs;
-
int elems_count;
int point_count;
+} ParticleHairCache;
+
+typedef struct ParticleBatchCache {
+ /* Object mode strands for hair and points for particle,
+ * strands for paths when in edit mode.
+ */
+ ParticleHairCache hair; /* Used for hair strands */
+ ParticlePointCache point; /* Used for particle points. */
/* Control points when in edit mode. */
+ ParticleHairCache edit_hair;
+
Gwn_VertBuf *edit_inner_pos;
Gwn_Batch *edit_inner_points;
int edit_inner_point_count;
@@ -146,6 +159,19 @@ void DRW_particle_batch_cache_dirty(ParticleSystem *psys, int mode)
}
}
+static void particle_batch_cache_clear_point(ParticlePointCache *point_cache)
+{
+ GWN_BATCH_DISCARD_SAFE(point_cache->points);
+ GWN_VERTBUF_DISCARD_SAFE(point_cache->pos);
+}
+
+static void particle_batch_cache_clear_hair(ParticleHairCache *hair_cache)
+{
+ GWN_BATCH_DISCARD_SAFE(hair_cache->hairs);
+ GWN_VERTBUF_DISCARD_SAFE(hair_cache->pos);
+ GWN_INDEXBUF_DISCARD_SAFE(hair_cache->indices);
+}
+
static void particle_batch_cache_clear(ParticleSystem *psys)
{
ParticleBatchCache *cache = psys->batch_cache;
@@ -153,10 +179,10 @@ static void particle_batch_cache_clear(ParticleSystem *psys)
return;
}
- GWN_BATCH_DISCARD_SAFE(cache->hairs);
- GWN_VERTBUF_DISCARD_SAFE(cache->pos);
- GWN_INDEXBUF_DISCARD_SAFE(cache->indices);
+ particle_batch_cache_clear_point(&cache->point);
+ particle_batch_cache_clear_hair(&cache->hair);
+ particle_batch_cache_clear_hair(&cache->edit_hair);
GWN_BATCH_DISCARD_SAFE(cache->edit_inner_points);
GWN_VERTBUF_DISCARD_SAFE(cache->edit_inner_pos);
GWN_BATCH_DISCARD_SAFE(cache->edit_tip_points);
@@ -171,38 +197,40 @@ void DRW_particle_batch_cache_free(ParticleSystem *psys)
static void count_cache_segment_keys(ParticleCacheKey **pathcache,
const int num_path_cache_keys,
- ParticleBatchCache *cache)
+ ParticleHairCache *hair_cache)
{
for (int i = 0; i < num_path_cache_keys; i++) {
ParticleCacheKey *path = pathcache[i];
if (path->segments > 0) {
- cache->elems_count += path->segments + 2;
- cache->point_count += path->segments + 1;
+ hair_cache->elems_count += path->segments + 2;
+ hair_cache->point_count += path->segments + 1;
}
}
}
static void ensure_seg_pt_count(PTCacheEdit *edit,
ParticleSystem *psys,
- ParticleBatchCache *cache)
+ ParticleHairCache *hair_cache)
{
- if (cache->pos == NULL || cache->indices == NULL) {
- cache->elems_count = 0;
- cache->point_count = 0;
+ if (hair_cache->pos != NULL && hair_cache->indices != NULL) {
+ return;
+ }
+
+ hair_cache->elems_count = 0;
+ hair_cache->point_count = 0;
- if (edit != NULL && edit->pathcache != NULL) {
- count_cache_segment_keys(edit->pathcache, edit->totcached, cache);
+ if (edit != NULL && edit->pathcache != NULL) {
+ count_cache_segment_keys(edit->pathcache, edit->totcached, hair_cache);
+ }
+ else {
+ if (psys->pathcache &&
+ (!psys->childcache || (psys->part->draw & PART_DRAW_PARENT)))
+ {
+ count_cache_segment_keys(psys->pathcache, psys->totpart, hair_cache);
}
- else {
- if (psys->pathcache &&
- (!psys->childcache || (psys->part->draw & PART_DRAW_PARENT)))
- {
- count_cache_segment_keys(psys->pathcache, psys->totpart, cache);
- }
- if (psys->childcache) {
- const int child_count = psys->totchild * psys->part->disp / 100;
- count_cache_segment_keys(psys->childcache, child_count, cache);
- }
+ if (psys->childcache) {
+ const int child_count = psys->totchild * psys->part->disp / 100;
+ count_cache_segment_keys(psys->childcache, child_count, hair_cache);
}
}
}
@@ -332,7 +360,7 @@ static int particle_batch_cache_fill_segments(
float (***r_parent_uvs)[2],
Gwn_IndexBufBuilder *elb,
HairAttributeID *attr_id,
- ParticleBatchCache *cache)
+ ParticleHairCache *hair_cache)
{
const bool is_simple = (psys->part->childtype == PART_CHILD_PARTICLES);
const bool is_child = (particle_source == PARTICLE_SOURCE_CHILDREN);
@@ -363,13 +391,13 @@ static int particle_batch_cache_fill_segments(
else {
sub_v3_v3v3(tangent, path[j + 1].co, path[j - 1].co);
}
- GWN_vertbuf_attr_set(cache->pos, attr_id->pos, curr_point, path[j].co);
- GWN_vertbuf_attr_set(cache->pos, attr_id->tan, curr_point, tangent);
- GWN_vertbuf_attr_set(cache->pos, attr_id->ind, curr_point, &i);
+ GWN_vertbuf_attr_set(hair_cache->pos, attr_id->pos, curr_point, path[j].co);
+ GWN_vertbuf_attr_set(hair_cache->pos, attr_id->tan, curr_point, tangent);
+ GWN_vertbuf_attr_set(hair_cache->pos, attr_id->ind, curr_point, &i);
if (psmd != NULL) {
for (int k = 0; k < num_uv_layers; k++) {
GWN_vertbuf_attr_set(
- cache->pos, uv_id[k], curr_point,
+ hair_cache->pos, uv_id[k], curr_point,
(is_simple && is_child)
? (*r_parent_uvs)[psys->child[i].parent][k]
: uv[k]);
@@ -381,14 +409,14 @@ static int particle_batch_cache_fill_segments(
sub_v3_v3v3(tangent, path[path->segments].co, path[path->segments - 1].co);
int global_index = i + global_offset;
- GWN_vertbuf_attr_set(cache->pos, attr_id->pos, curr_point, path[path->segments].co);
- GWN_vertbuf_attr_set(cache->pos, attr_id->tan, curr_point, tangent);
- GWN_vertbuf_attr_set(cache->pos, attr_id->ind, curr_point, &global_index);
+ GWN_vertbuf_attr_set(hair_cache->pos, attr_id->pos, curr_point, path[path->segments].co);
+ GWN_vertbuf_attr_set(hair_cache->pos, attr_id->tan, curr_point, tangent);
+ GWN_vertbuf_attr_set(hair_cache->pos, attr_id->ind, curr_point, &global_index);
if (psmd != NULL) {
for (int k = 0; k < num_uv_layers; k++) {
GWN_vertbuf_attr_set(
- cache->pos, uv_id[k], curr_point,
+ hair_cache->pos, uv_id[k], curr_point,
(is_simple && is_child) ?
(*r_parent_uvs)[psys->child[i].parent][k] :
uv[k]);
@@ -408,17 +436,17 @@ static int particle_batch_cache_fill_segments(
static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit,
ParticleSystem *psys,
ModifierData *md,
- ParticleBatchCache *cache)
+ ParticleHairCache *hair_cache)
{
- if (cache->pos != NULL && cache->indices != NULL) {
+ if (hair_cache->pos != NULL && hair_cache->indices != NULL) {
return;
}
int curr_point = 0;
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
- GWN_VERTBUF_DISCARD_SAFE(cache->pos);
- GWN_INDEXBUF_DISCARD_SAFE(cache->indices);
+ GWN_VERTBUF_DISCARD_SAFE(hair_cache->pos);
+ GWN_INDEXBUF_DISCARD_SAFE(hair_cache->indices);
static Gwn_VertFormat format = { 0 };
static HairAttributeID attr_id;
@@ -452,11 +480,14 @@ static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit,
}
}
- cache->pos = GWN_vertbuf_create_with_format(&format);
- GWN_vertbuf_data_alloc(cache->pos, cache->point_count);
+ hair_cache->pos = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(hair_cache->pos, hair_cache->point_count);
Gwn_IndexBufBuilder elb;
- GWN_indexbuf_init_ex(&elb, GWN_PRIM_LINE_STRIP, cache->elems_count, cache->point_count, true);
+ GWN_indexbuf_init_ex(&elb,
+ GWN_PRIM_LINE_STRIP,
+ hair_cache->elems_count, hair_cache->point_count,
+ true);
if (num_uv_layers) {
DM_ensure_tessface(psmd->dm_final);
@@ -471,7 +502,7 @@ static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit,
psys, psmd, edit->pathcache, PARTICLE_SOURCE_PARENT,
0, 0, edit->totcached,
num_uv_layers, mtfaces, uv_id, &parent_uvs,
- &elb, &attr_id, cache);
+ &elb, &attr_id, hair_cache);
}
else {
if ((psys->pathcache != NULL) &&
@@ -481,15 +512,15 @@ static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit,
psys, psmd, psys->pathcache, PARTICLE_SOURCE_PARENT,
0, 0, psys->totpart,
num_uv_layers, mtfaces, uv_id, &parent_uvs,
- &elb, &attr_id, cache);
+ &elb, &attr_id, hair_cache);
}
- if (psys->childcache) {
+ if (psys->childcache != NULL) {
const int child_count = psys->totchild * psys->part->disp / 100;
curr_point = particle_batch_cache_fill_segments(
psys, psmd, psys->childcache, PARTICLE_SOURCE_CHILDREN,
psys->totpart, curr_point, child_count,
num_uv_layers, mtfaces, uv_id, &parent_uvs,
- &elb, &attr_id, cache);
+ &elb, &attr_id, hair_cache);
}
}
/* Cleanup. */
@@ -506,12 +537,14 @@ static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit,
if (psmd != NULL) {
MEM_freeN(uv_id);
}
- cache->indices = GWN_indexbuf_build(&elb);
+ hair_cache->indices = GWN_indexbuf_build(&elb);
}
-static void particle_batch_cache_ensure_pos(Object *object, ParticleSystem *psys, ParticleBatchCache *cache)
+static void particle_batch_cache_ensure_pos(Object *object,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list