[Bf-blender-cvs] [b2eb76cd50c] blender2.8: Dopesheet-Timeline: Ported over cache indicator drawing + settings used to control their visibility

Joshua Leung noreply at git.blender.org
Fri Apr 20 19:06:37 CEST 2018


Commit: b2eb76cd50c98b6964ade51a486d31e8b40110dd
Author: Joshua Leung
Date:   Thu Apr 19 16:04:26 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBb2eb76cd50c98b6964ade51a486d31e8b40110dd

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.

===================================================================

M	source/blender/editors/space_action/action_draw.c
M	source/blender/editors/space_action/action_intern.h
M	source/blender/editors/space_action/space_action.c
M	source/blender/makesdna/DNA_action_types.h
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

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);
 
diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h
index f08199ad957..3c035ae0bc8 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -680,6 +680,9 @@ typedef struct SpaceAction {
 	char mode, autosnap;        /* mode: editing context; autosnap: automatic keyframe snapping mode   */
 	short flag;                 /* flag: bitmapped settings; */
 	float timeslide;            /* for Time-Slide transform mode drawing - current frame? */
+	
+	int cache_display;          /* (eTimeline_Cache_Flag) */
+	int pad;
 } SpaceAction;
 
 /* SpaceAction flag */
@@ -744,6 +747,17 @@ typedef enum eAnimEdit_AutoSnap {
 	SACTSNAP_TSTEP = 5
 } eAnimEdit_AutoSnap;
 
+/* SAction->cache_display */
+typedef enum eTimeline_Cache_Flag {
+	TIME_CACHE_DISPLAY       = (1 << 0),
+	TIME_CACHE_SOFTBODY      = (1 << 1),
+	TIME_CACHE_PARTICLES     = (1 << 2),
+	TIME_CACHE_CLOTH         = (1 << 3),
+	TIME_CACHE_SMOKE         = (1 << 4),
+	TIME_CACHE_DYNAMICPAINT  = (1 << 5),
+	TIME_CACHE_RIGIDBODY     = (1 << 6),
+} eTimeline_Cache_Flag;
+
 
 /* ************************************************ */
 /* Legacy Data */
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index a532dff190c..284e6ff9154 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -524,16 +524,6 @@ typedef enum eScreen_Redraws_Flag {
 	TIME_FOLLOW            = (1 << 15),
 } eScreen_Redraws_Flag;
 
-/* time->cache */
-typedef enum eTimeline_Cache_Flag {
-	TIME_CACHE_DISPLAY       = (1 << 0),
-	TIME_CACHE_SOFTBODY      = (1 << 1),
-	TIME_CACHE_PARTICLES     = (1 << 2),
-	TIME_CACHE_CLOTH         = (1 << 3),
-	TIME_CACHE_SMOKE         = (1 << 4),
-	TIME_CACHE_DYNAMICPAINT  = (1 << 5),
-	TIME_CACHE_RIGIDBODY     = (1 << 6),
-} eTimeline_Cache_Flag;
 
 
 /* Sequence Editor ======================================= */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 7ac6ed35068..9c212d359aa 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -3271,6 +3271,42 @@ static void rna_def_space_dopesheet(BlenderRNA *brna)
 	RNA_def_property_enum_items(prop, autosnap_items);
 	RNA_def_property_ui_text(prop, "Auto Snap", "Automatic time snapping settings for transformations");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_DOPESHEET, NULL);
+	
+	/* displaying cache status */
+	prop = RNA_def_property(srna, "show_cache", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_DISPLAY);
+	RNA_def_property_ui_text(prop, "Show Cache", "Show the status of cached frames in the timeline");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
+
+	prop = RNA_def_property(srna, "cache_softbody", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, N

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list