Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2018-05-09 15:08:44 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2018-05-09 15:59:48 +0300
commit5cea8bf4355dbe9d0ad5170d123b15e9babfa51a (patch)
treed569964e729c75b3bb76ad3f9bf610ae9e66e87b /source/blender/draw/intern/draw_cache_impl_particles.c
parent033c2c71312daf86a148a068a2e20afcb784b3ee (diff)
Draw manager: Initial implementation of key points visualization
Does all points all the time, ignoring the setting in viewport header. This is to be addressed by the next commit.
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_particles.c')
-rw-r--r--source/blender/draw/intern/draw_cache_impl_particles.c93
1 files changed, 87 insertions, 6 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index 0cc3c001ef2..065628f3f68 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -59,15 +59,22 @@ 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.
+ */
Gwn_VertBuf *pos;
Gwn_IndexBuf *indices;
-
Gwn_Batch *hairs;
int elems_count;
int point_count;
- /* settings to determine if cache is invalid */
+ /* Control points when in edit mode. */
+ Gwn_VertBuf *edit_pos;
+ Gwn_Batch *edit_points;
+ int edit_point_count;
+
+ /* Settings to determine if cache is invalid. */
bool is_dirty;
} ParticleBatchCache;
@@ -143,9 +150,11 @@ static void particle_batch_cache_clear(ParticleSystem *psys)
}
GWN_BATCH_DISCARD_SAFE(cache->hairs);
-
GWN_VERTBUF_DISCARD_SAFE(cache->pos);
GWN_INDEXBUF_DISCARD_SAFE(cache->indices);
+
+ GWN_BATCH_DISCARD_SAFE(cache->edit_points);
+ GWN_VERTBUF_DISCARD_SAFE(cache->edit_pos);
}
void DRW_particle_batch_cache_free(ParticleSystem *psys)
@@ -173,7 +182,7 @@ static void ensure_seg_pt_count(ParticleSystem *psys, ParticleBatchCache *cache)
cache->elems_count = 0;
cache->point_count = 0;
- PTCacheEdit* edit = PE_get_current_from_psys(psys);
+ PTCacheEdit *edit = PE_get_current_from_psys(psys);
if (edit != NULL && edit->pathcache != NULL) {
count_cache_segment_keys(edit->pathcache, psys->totpart, cache);
} else {
@@ -436,7 +445,7 @@ static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys,
}
}
- PTCacheEdit* edit = PE_get_current_from_psys(psys);
+ PTCacheEdit *edit = PE_get_current_from_psys(psys);
if (edit != NULL && edit->pathcache != NULL) {
curr_point = particle_batch_cache_fill_segments(
psys, psmd, edit->pathcache, PARTICLE_SOURCE_PARENT,
@@ -578,7 +587,7 @@ Gwn_Batch *DRW_particles_batch_cache_get_dots(Object *object, ParticleSystem *ps
return cache->hairs;
}
-Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(PTCacheEdit* edit)
+Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(PTCacheEdit *edit)
{
ParticleSystem *psys = edit->psys;
ParticleBatchCache *cache = particle_batch_cache_get(psys);
@@ -590,3 +599,75 @@ Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(PTCacheEdit* edit)
cache->hairs = GWN_batch_create(GWN_PRIM_LINE_STRIP, cache->pos, cache->indices);
return cache->hairs;
}
+
+static void ensure_edit_points_count(const PTCacheEdit *edit,
+ ParticleBatchCache *cache)
+{
+ if (cache->edit_pos != NULL) {
+ return;
+ }
+ cache->edit_point_count = 0;
+ for (int point_index = 0; point_index < edit->totpoint; point_index++) {
+ const PTCacheEditPoint *point = &edit->points[point_index];
+ cache->edit_point_count += point->totkey;
+ }
+}
+
+static void particle_batch_cache_ensure_edit_pos(PTCacheEdit *edit,
+ ParticleBatchCache *cache)
+{
+ if (cache->edit_pos != NULL) {
+ return;
+ }
+
+ static Gwn_VertFormat format = { 0 };
+ static unsigned pos_id, color_id;
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->edit_pos);
+
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ color_id = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ }
+
+ cache->edit_pos = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(cache->edit_pos, cache->edit_point_count);
+
+ /* Convert theme colors from uchar[3] to float[4]. */
+ float selected_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ float normal_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ rgb_uchar_to_float(selected_color, edit->sel_col);
+ rgb_uchar_to_float(normal_color, edit->nosel_col);
+
+ int global_key_index = 0;
+ for (int point_index = 0; point_index < edit->totpoint; point_index++) {
+ const PTCacheEditPoint *point = &edit->points[point_index];
+ for (int key_index = 0; key_index < point->totkey; key_index++) {
+ PTCacheEditKey *key = &point->keys[key_index];
+ GWN_vertbuf_attr_set(cache->edit_pos, pos_id, global_key_index, key->world_co);
+ if (key->flag & PEK_SELECT) {
+ GWN_vertbuf_attr_set(cache->edit_pos, color_id, global_key_index, selected_color);
+ }
+ else {
+ GWN_vertbuf_attr_set(cache->edit_pos, color_id, global_key_index, normal_color);
+ }
+ global_key_index++;
+ }
+ }
+}
+
+Gwn_Batch *DRW_particles_batch_cache_get_edit_points(PTCacheEdit *edit)
+{
+ ParticleSystem *psys = edit->psys;
+ ParticleBatchCache *cache = particle_batch_cache_get(psys);
+ if (cache->edit_points != NULL) {
+ return cache->edit_points;
+ }
+ ensure_edit_points_count(edit, cache);
+ particle_batch_cache_ensure_edit_pos(edit, cache);
+ cache->edit_points = GWN_batch_create(GWN_PRIM_POINTS,
+ cache->edit_pos,
+ NULL);
+ return cache->edit_points;
+}