[Bf-blender-cvs] [d8203b04228] tmp-b28-motionpath-drawing: Motion Paths: Port motion path to draw manager (1/2)

Clément Foucault noreply at git.blender.org
Thu May 31 00:17:40 CEST 2018


Commit: d8203b04228a3a5c8b447fe0218f03083ea1588f
Author: Clément Foucault
Date:   Thu May 31 00:25:23 2018 +0200
Branches: tmp-b28-motionpath-drawing
https://developer.blender.org/rBd8203b04228a3a5c8b447fe0218f03083ea1588f

Motion Paths: Port motion path to draw manager (1/2)

Add keyframe drawing by baking the keyframe position in the motion path vert
cache.

Only remaining problem is that toggling the pose bone MOTIONPATH_VIEW_KFACT
needs a motion path recalc now.

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

M	source/blender/blenkernel/intern/anim.c
M	source/blender/draw/intern/draw_anim_viz.c
M	source/blender/draw/modes/shaders/animviz_mpath_points_vert.glsl
M	source/blender/makesdna/DNA_action_types.h

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

diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index 1f325429158..674cf545ec6 100644
--- a/source/blender/blenkernel/intern/anim.c
+++ b/source/blender/blenkernel/intern/anim.c
@@ -35,6 +35,7 @@
 
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_dlrbTree.h"
 
 #include "BLT_translation.h"
 
@@ -44,6 +45,7 @@
 #include "DNA_scene_types.h"
 
 #include "BKE_anim.h"
+#include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_context.h"
 #include "BKE_curve.h"
@@ -62,6 +64,9 @@
 #include "GPU_batch.h"
 
 // XXX bad level call...
+extern short compare_ak_cfraPtr(void *node, void *data);
+extern void agroup_to_keylist(struct AnimData *adt, struct bActionGroup *agrp, struct DLRBT_Tree *keys, struct DLRBT_Tree *blocks);
+extern void action_to_keylist(struct AnimData *adt, struct bAction *act, struct DLRBT_Tree *keys, struct DLRBT_Tree *blocks);
 
 /* --------------------- */
 /* forward declarations */
@@ -109,20 +114,12 @@ void animviz_free_motionpath_cache(bMotionPath *mpath)
 	if (mpath->points)
 		MEM_freeN(mpath->points);
 
-	if (mpath->points_vbo)
-		GWN_vertbuf_discard(mpath->points_vbo);
-
-	if (mpath->batch_line)
-		GWN_batch_discard(mpath->batch_line);
-
-	if (mpath->batch_points)
-		GWN_batch_discard(mpath->batch_points);
+	GWN_VERTBUF_DISCARD_SAFE(mpath->points_vbo);
+	GWN_BATCH_DISCARD_SAFE(mpath->batch_line);
+	GWN_BATCH_DISCARD_SAFE(mpath->batch_points);
 	
 	/* reset the relevant parameters */
 	mpath->points = NULL;
-	mpath->points_vbo = NULL;
-	mpath->batch_line = NULL;
-	mpath->batch_points = NULL;
 	mpath->length = 0;
 }
 
@@ -246,6 +243,8 @@ typedef struct MPathTarget {
 	struct MPathTarget *next, *prev;
 	
 	bMotionPath *mpath;         /* motion path in question */
+
+	DLRBT_Tree keys;         /* temp, to know where the keyframes are */
 	
 	/* Original (Source Objects) */
 	Object *ob;                 /* source object */
@@ -358,6 +357,13 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
 			/* worldspace object location */
 			copy_v3_v3(mpv->co, ob_eval->obmat[3]);
 		}
+
+		float mframe = (float)(CFRA);
+
+		/* Tag if it's a keyframe */
+		if (BLI_dlrbTree_search_exact(&mpt->keys, compare_ak_cfraPtr, &mframe)) {
+			mpv->flag |= MOTIONPATH_VERT_KEY;
+		}
 	}
 }
 
@@ -401,13 +407,44 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
 		if (mpt->pchan) {
 			mpt->pchan_eval = BKE_pose_channel_find_name(mpt->ob_eval->pose, mpt->pchan->name);
 		}
+
+		AnimData *adt = BKE_animdata_from_id(&mpt->ob_eval->id);
+
+		/* build list of all keyframes in active action for object or pchan */
+		BLI_dlrbTree_init(&mpt->keys);
+
+		if (adt) {
+			bAnimVizSettings *avs;
+
+			/* get pointer to animviz settings for each target */
+			if (mpt->pchan)
+				avs = &mpt->ob->pose->avs;
+			else
+				avs = &mpt->ob->avs;
+
+			/* it is assumed that keyframes for bones are all grouped in a single group
+			 * unless an option is set to always use the whole action
+			 */
+			if ((mpt->pchan) && (avs->path_viewflag & MOTIONPATH_VIEW_KFACT) == 0) {
+				bActionGroup *agrp = BKE_action_group_find_name(adt->action, mpt->pchan->name);
+
+				if (agrp) {
+					agroup_to_keylist(adt, agrp, &mpt->keys, NULL);
+					BLI_dlrbTree_linkedlist_sync(&mpt->keys);
+				}
+			}
+			else {
+				action_to_keylist(adt, adt->action, &mpt->keys, NULL);
+				BLI_dlrbTree_linkedlist_sync(&mpt->keys);
+			}
+		}
 	}
-	
+
 	/* calculate path over requested range */
 	for (CFRA = sfra; CFRA <= efra; CFRA++) {
 		/* update relevant data for new frame */
 		motionpaths_calc_update_scene(bmain, depsgraph);
-		
+
 		/* perform baking for targets */
 		motionpaths_calc_bake_targets(scene, targets);
 	}
@@ -420,6 +457,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
 	/* clear recalc flags from targets */
 	for (mpt = targets->first; mpt; mpt = mpt->next) {
 		bAnimVizSettings *avs;
+		bMotionPath *mpath = mpt->mpath;
 		
 		/* get pointer to animviz settings for each target */
 		if (mpt->pchan)
@@ -429,6 +467,14 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
 		
 		/* clear the flag requesting recalculation of targets */
 		avs->recalc &= ~ANIMVIZ_RECALC_PATHS;
+
+		/* Clean temp data */
+		BLI_dlrbTree_free(&mpt->keys);
+
+		/* Free previous batches to force update. */
+		GWN_VERTBUF_DISCARD_SAFE(mpath->points_vbo);
+		GWN_BATCH_DISCARD_SAFE(mpath->batch_line);
+		GWN_BATCH_DISCARD_SAFE(mpath->batch_points);
 	}
 }
 
diff --git a/source/blender/draw/intern/draw_anim_viz.c b/source/blender/draw/intern/draw_anim_viz.c
index 534e3752e86..33d4472cdfc 100644
--- a/source/blender/draw/intern/draw_anim_viz.c
+++ b/source/blender/draw/intern/draw_anim_viz.c
@@ -102,7 +102,7 @@ static Gwn_VertBuf *mpath_vbo_get(bMotionPath *mpath)
 		Gwn_VertFormat format = {0};
 		/* Match structure of bMotionPathVert. */
 		uint pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-		GWN_vertformat_attr_add(&format, "flag", GWN_COMP_U32, 1, GWN_FETCH_INT);
+		GWN_vertformat_attr_add(&format, "flag", GWN_COMP_I32, 1, GWN_FETCH_INT);
 		mpath->points_vbo = GWN_vertbuf_create_with_format(&format);
 		GWN_vertbuf_data_alloc(mpath->points_vbo, mpath->length);
 
@@ -628,24 +628,29 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl, Scene *scene,
 	DRW_shgroup_call_range_add(shgrp, mpath_batch_points_get(mpath), NULL, sind, len);
 
 	/* Draw frame numbers at each framestep value */
-	if (avs->path_viewflag & MOTIONPATH_VIEW_FNUMS) {
+	bool show_kf_no = (avs->path_viewflag & MOTIONPATH_VIEW_KFNOS) != 0;
+	if ((avs->path_viewflag & (MOTIONPATH_VIEW_FNUMS)) || (show_kf_no && show_keyframes)) {
 		int i;
-		unsigned char col[4];
+		unsigned char col[4], col_kf[4];
 		UI_GetThemeColor3ubv(TH_TEXT_HI, col);
-		col[3] = 255;
+		UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col_kf);
+		col[3] = col_kf[3] = 255;
 
 		for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize) {
 			int frame = sfra + i;
 			char numstr[32];
 			size_t numstr_len;
 			float co[3];
+			bool is_keyframe = (mpv->flag & MOTIONPATH_VERT_KEY) != 0;
 
-			if (i == 0) {
+			if ((show_keyframes && show_kf_no && is_keyframe) ||
+			    ((avs->path_viewflag & MOTIONPATH_VIEW_FNUMS) && (i == 0)))
+			{
 				numstr_len = sprintf(numstr, " %d", frame);
 				mul_v3_m4v3(co, ob->imat, mpv->co);
-				DRW_text_cache_add(dt, co, numstr, numstr_len, 0, txt_flag, col);
+				DRW_text_cache_add(dt, co, numstr, numstr_len, 0, txt_flag, (is_keyframe) ? col_kf : col);
 			}
-			else {
+			else if (avs->path_viewflag & MOTIONPATH_VIEW_FNUMS) {
 				bMotionPathVert *mpvP = (mpv - stepsize);
 				bMotionPathVert *mpvN = (mpv + stepsize);
 				/* only draw framenum if several consecutive highlighted points don't occur on same point */
diff --git a/source/blender/draw/modes/shaders/animviz_mpath_points_vert.glsl b/source/blender/draw/modes/shaders/animviz_mpath_points_vert.glsl
index 57fee67538e..3b2f170ca22 100644
--- a/source/blender/draw/modes/shaders/animviz_mpath_points_vert.glsl
+++ b/source/blender/draw/modes/shaders/animviz_mpath_points_vert.glsl
@@ -11,21 +11,37 @@ uniform vec3 customColor;
 in vec3 pos;
 in int flag;
 
+#define MOTIONPATH_VERT_SEL (1 << 0)
+#define MOTIONPATH_VERT_KEY (1 << 1)
+
 out vec4 finalColor;
 
 void main()
 {
 	gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
-	gl_PointSize = float(pointSize + 3);
+	gl_PointSize = float(pointSize + 2);
 
 	int frame = gl_VertexID + cacheStart;
 	finalColor = (useCustomColor) ? vec4(customColor, 1.0) : vec4(1.0);
 
-	/* Draw big green dot where the current frame is.
-	 * NOTE: this is only done when keyframes are shown, since this adds similar types of clutter
-	 */
-	if (frame == frameCurrent) {
-		gl_PointSize = float(pointSize + 7);
-		finalColor = colorCurrentFrame;
+	/* Bias to reduce z fighting with the path */
+	gl_Position.z -= 1e-4;
+
+	if (showKeyFrames) {
+		if ((flag & MOTIONPATH_VERT_KEY) != 0) {
+			gl_PointSize = float(pointSize + 5);
+			finalColor = colorVertexSelect;
+			/* Bias more to get these on top of regular points */
+			gl_Position.z -= 1e-4;
+		}
+		/* Draw big green dot where the current frame is.
+		 * NOTE: this is only done when keyframes are shown, since this adds similar types of clutter
+		 */
+		if (frame == frameCurrent) {
+			gl_PointSize = float(pointSize + 8);
+			finalColor = colorCurrentFrame;
+			/* Bias more to get these on top of keyframes */
+			gl_Position.z -= 1e-4;
+		}
 	}
 }
diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h
index 22c19e2b42b..7a38cff16ad 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -61,7 +61,8 @@ typedef struct bMotionPathVert {
 /* bMotionPathVert->flag */
 typedef enum eMotionPathVert_Flag {
 	/* vert is selected */
-	MOTIONPATH_VERT_SEL     = (1 << 0)
+	MOTIONPATH_VERT_SEL     = (1 << 0),
+	MOTIONPATH_VERT_KEY     = (1 << 1),
 } eMotionPathVert_Flag;
 
 /* ........ */



More information about the Bf-blender-cvs mailing list