diff options
author | Joshua Leung <aligorith@gmail.com> | 2018-04-19 17:04:26 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2018-04-20 19:54:40 +0300 |
commit | b2eb76cd50c98b6964ade51a486d31e8b40110dd (patch) | |
tree | 910ea1279b0434b76f83a22a88aab7587591054c /source/blender/editors | |
parent | cc06e0fbe8bf122a7f1688342f9e80df3be8502f (diff) |
Dopesheet-Timeline: Ported over cache indicator drawing + settings used to control their visibility
These now live in the action editor/dopesheet related files.
Apart from these, the timeline didn't actually have other settings
of its own that were of any interest to anyone.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_action/action_draw.c | 144 | ||||
-rw-r--r-- | source/blender/editors/space_action/action_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/space_action/space_action.c | 13 |
3 files changed, 160 insertions, 1 deletions
diff --git a/source/blender/editors/space_action/action_draw.c b/source/blender/editors/space_action/action_draw.c index 11ac1d60f39..b4005faf2f3 100644 --- a/source/blender/editors/space_action/action_draw.c +++ b/source/blender/editors/space_action/action_draw.c @@ -43,16 +43,23 @@ /* Types --------------------------------------------------------------- */ #include "DNA_anim_types.h" +#include "DNA_cachefile_types.h" +#include "DNA_object_types.h" #include "DNA_screen_types.h" +#include "DNA_scene_types.h" #include "BKE_action.h" #include "BKE_context.h" +#include "BKE_pointcache.h" /* Everything from source (BIF, BDR, BSE) ------------------------------ */ #include "BIF_gl.h" +#include "GPU_immediate.h" +#include "GPU_matrix.h" + #include "UI_interface.h" #include "UI_resources.h" #include "UI_view2d.h" @@ -61,7 +68,6 @@ #include "ED_keyframes_draw.h" #include "action_intern.h" -#include "GPU_immediate.h" /* ************************************************************************* */ /* Channel List */ @@ -381,3 +387,139 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar) /* free temporary channels used for drawing */ ANIM_animdata_freelist(&anim_data); } + +/* ************************************************************************* */ +/* Timeline - Caches */ + +void timeline_draw_cache(SpaceAction *saction, Object *ob, Scene *scene) +{ + PTCacheID *pid; + ListBase pidlist; + const float cache_draw_height = (4.0f * UI_DPI_FAC * U.pixelsize); + float yoffs = 0.f; + + if (!(saction->cache_display & TIME_CACHE_DISPLAY) || (!ob)) + return; + + BKE_ptcache_ids_from_object(&pidlist, ob, scene, 0); + + unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + /* iterate over pointcaches on the active object, + * add spacetimecache and vertex array for each */ + for (pid = pidlist.first; pid; pid = pid->next) { + float col[4]; + + switch (pid->type) { + case PTCACHE_TYPE_SOFTBODY: + if (!(saction->cache_display & TIME_CACHE_SOFTBODY)) continue; + break; + case PTCACHE_TYPE_PARTICLES: + if (!(saction->cache_display & TIME_CACHE_PARTICLES)) continue; + break; + case PTCACHE_TYPE_CLOTH: + if (!(saction->cache_display & TIME_CACHE_CLOTH)) continue; + break; + case PTCACHE_TYPE_SMOKE_DOMAIN: + case PTCACHE_TYPE_SMOKE_HIGHRES: + if (!(saction->cache_display & TIME_CACHE_SMOKE)) continue; + break; + case PTCACHE_TYPE_DYNAMICPAINT: + if (!(saction->cache_display & TIME_CACHE_DYNAMICPAINT)) continue; + break; + case PTCACHE_TYPE_RIGIDBODY: + if (!(saction->cache_display & TIME_CACHE_RIGIDBODY)) continue; + break; + } + + if (pid->cache->cached_frames == NULL) + continue; + + gpuPushMatrix(); + gpuTranslate2f(0.0, (float)V2D_SCROLL_HEIGHT + yoffs); + gpuScale2f(1.0, cache_draw_height); + + switch (pid->type) { + case PTCACHE_TYPE_SOFTBODY: + col[0] = 1.0; col[1] = 0.4; col[2] = 0.02; + col[3] = 0.1; + break; + case PTCACHE_TYPE_PARTICLES: + col[0] = 1.0; col[1] = 0.1; col[2] = 0.02; + col[3] = 0.1; + break; + case PTCACHE_TYPE_CLOTH: + col[0] = 0.1; col[1] = 0.1; col[2] = 0.75; + col[3] = 0.1; + break; + case PTCACHE_TYPE_SMOKE_DOMAIN: + case PTCACHE_TYPE_SMOKE_HIGHRES: + col[0] = 0.2; col[1] = 0.2; col[2] = 0.2; + col[3] = 0.1; + break; + case PTCACHE_TYPE_DYNAMICPAINT: + col[0] = 1.0; col[1] = 0.1; col[2] = 0.75; + col[3] = 0.1; + break; + case PTCACHE_TYPE_RIGIDBODY: + col[0] = 1.0; col[1] = 0.6; col[2] = 0.0; + col[3] = 0.1; + break; + default: + col[0] = 1.0; col[1] = 0.0; col[2] = 1.0; + col[3] = 0.1; + BLI_assert(0); + break; + } + + const int sta = pid->cache->startframe, end = pid->cache->endframe; + const int len = (end - sta + 1) * 6; + + glEnable(GL_BLEND); + + immUniformColor4fv(col); + immRectf(pos, (float)sta, 0.0, (float)end, 1.0); + + col[3] = 0.4f; + if (pid->cache->flag & PTCACHE_BAKED) { + col[0] -= 0.4f; col[1] -= 0.4f; col[2] -= 0.4f; + } + else if (pid->cache->flag & PTCACHE_OUTDATED) { + col[0] += 0.4f; col[1] += 0.4f; col[2] += 0.4f; + } + + immUniformColor4fv(col); + + if (len > 0) { + immBeginAtMost(GWN_PRIM_TRIS, len); + + /* draw a quad for each cached frame */ + for (int i = sta; i <= end; i++) { + if (pid->cache->cached_frames[i - sta]) { + immVertex2f(pos, (float)i - 0.5f, 0.0f); + immVertex2f(pos, (float)i - 0.5f, 1.0f); + immVertex2f(pos, (float)i + 0.5f, 1.0f); + + immVertex2f(pos, (float)i - 0.5f, 0.0f); + immVertex2f(pos, (float)i + 0.5f, 1.0f); + immVertex2f(pos, (float)i + 0.5f, 0.0f); + } + } + + immEnd(); + } + + glDisable(GL_BLEND); + + gpuPopMatrix(); + + yoffs += cache_draw_height; + } + + immUnbindProgram(); + + BLI_freelistN(&pidlist); +} + +/* ************************************************************************* */ diff --git a/source/blender/editors/space_action/action_intern.h b/source/blender/editors/space_action/action_intern.h index 408eb38d386..29c53815b3a 100644 --- a/source/blender/editors/space_action/action_intern.h +++ b/source/blender/editors/space_action/action_intern.h @@ -33,6 +33,8 @@ struct bContext; struct bAnimContext; +struct Scene; +struct Object; struct SpaceAction; struct ScrArea; struct ARegion; @@ -54,6 +56,8 @@ void ACTION_OT_properties(struct wmOperatorType *ot); void draw_channel_names(struct bContext *C, struct bAnimContext *ac, struct ARegion *ar); void draw_channel_strips(struct bAnimContext *ac, struct SpaceAction *saction, struct ARegion *ar); +void timeline_draw_cache(struct SpaceAction *saction, struct Object *ob, struct Scene *scene); + /* ***************************************** */ /* action_select.c */ diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c index 50882571dad..7dce4f0f6fa 100644 --- a/source/blender/editors/space_action/space_action.c +++ b/source/blender/editors/space_action/space_action.c @@ -170,7 +170,14 @@ static void action_free(SpaceLink *UNUSED(sl)) static void action_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa) { SpaceAction *saction = sa->spacedata.first; + saction->flag |= SACTION_TEMP_NEEDCHANSYNC; + + /* enable all cache display */ + saction->cache_display |= TIME_CACHE_DISPLAY; + saction->cache_display |= (TIME_CACHE_SOFTBODY | TIME_CACHE_PARTICLES); + saction->cache_display |= (TIME_CACHE_CLOTH | TIME_CACHE_SMOKE | TIME_CACHE_DYNAMICPAINT); + saction->cache_display |= TIME_CACHE_RIGIDBODY; } static SpaceLink *action_duplicate(SpaceLink *sl) @@ -238,7 +245,13 @@ static void action_main_region_draw(const bContext *C, ARegion *ar) flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN; ED_markers_draw(C, flag); + /* caches */ + if (saction->mode == SACTCONT_TIMELINE) { + timeline_draw_cache(saction, ac.obact, ac.scene); + } + /* preview range */ + // XXX: we should always draw the range UI_view2d_view_ortho(v2d); ANIM_draw_previewrange(C, v2d, 0); |