[Bf-blender-cvs] [72a360827bc] blender2.8: T54991: Restore support for Motion Path drawing in 2.8

Joshua Leung noreply at git.blender.org
Fri Jun 1 16:38:25 CEST 2018


Commit: 72a360827bc47e68bf47a5aa4ad9185b031423c4
Author: Joshua Leung
Date:   Fri Jun 1 16:38:21 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB72a360827bc47e68bf47a5aa4ad9185b031423c4

T54991: Restore support for Motion Path drawing in 2.8

This commit restores support for Motion Path drawing in 2.8 (as it wasn't ported over
to the new draw engines earlier, and the existing space_view3d/drawanimviz.c code was
removed during the Blender Internal removal).

Notes:
* Motion Paths are now implemented as an overlay (enabled by default).
  Therefore, you can turn all of them on/off from the "Overlays" popover

* By and large, we have kept the same draw style as was used in 2.7
  Further changes can happen later following further design work.

* One change from 2.7 is that thicker lines are used by default (2px vs 1px)


Todo's:
* There are some bad-level calls introduced here (i.e. the actgroup_to_keylist() stuff).
  These were introduced to optimise drawing performance (by avoiding full keyframes -> keylist
  conversion step on each drawcall). Instead, this has been moved to the calculation step
  (in blenkernel).  Soon, there will be some cleanups/improvements with those functions,
  so until then, we'll keep the bad level calls.


Credits:
* Clément Foucault (fclem) - Draw Engine magic + Shader Conversion/Optimisation
* Joshua Leung (Aligorith) - COW fixes, UI integration, etc.


Revision History:
See "tmp-b28-motionpath_drawing" branch (rBa12ab5b2ef49ccacae091ccb54d72de0d63f990d)

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/action.c
M	source/blender/blenkernel/intern/anim.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/intern/DRW_render.h
A	source/blender/draw/intern/draw_anim_viz.c
M	source/blender/draw/intern/draw_common.c
M	source/blender/draw/intern/draw_common.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager.h
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/draw/intern/draw_manager_exec.c
M	source/blender/draw/modes/draw_mode_engines.h
A	source/blender/draw/modes/shaders/animviz_mpath_lines_geom.glsl
A	source/blender/draw/modes/shaders/animviz_mpath_lines_vert.glsl
A	source/blender/draw/modes/shaders/animviz_mpath_points_vert.glsl
M	source/blender/draw/modes/shaders/common_globals_lib.glsl
M	source/blender/editors/armature/pose_edit.c
M	source/blender/editors/object/object_edit.c
M	source/blender/makesdna/DNA_action_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index b93e24da87a..8e5ca798ac3 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3597,6 +3597,7 @@ class VIEW3D_PT_overlay(Panel):
         col.prop(overlay, "show_outline_selected")
         col.prop(overlay, "show_all_objects_origin")
         col.prop(overlay, "show_relationship_lines")
+        col.prop(overlay, "show_motion_paths")
         col.prop(overlay, "show_face_orientation")
         col.prop(overlay, "show_wireframes")
         col.prop(overlay, "show_backface_culling")
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 0fb83162459..701be9d44cc 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -48,6 +48,8 @@ struct Main;
 
 void animviz_settings_init(struct bAnimVizSettings *avs);
 
+struct bMotionPath *animviz_copy_motionpath(const struct bMotionPath *mpath_src);
+
 void animviz_free_motionpath_cache(struct bMotionPath *mpath);
 void animviz_free_motionpath(struct bMotionPath *mpath);
 
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 360d9c019ba..c12dd49b47e 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -582,7 +582,9 @@ void BKE_pose_copy_data_ex(bPose **dst, const bPose *src, const int flag, const
 		if (copy_constraints) {
 			BKE_constraints_copy_ex(&listb, &pchan->constraints, flag, true);  // BKE_constraints_copy NULLs listb
 			pchan->constraints = listb;
-			pchan->mpath = NULL; /* motion paths should not get copied yet... */
+
+			/* XXX: This is needed for motionpath drawing to work. Dunno why it was setting to null before... */
+			pchan->mpath = animviz_copy_motionpath(pchan->mpath);
 		}
 		
 		if (pchan->prop) {
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index cff9fd4a7c8..c7730d8877b 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"
@@ -59,7 +61,12 @@
 #include "DEG_depsgraph_query.h"
 #include "DEG_depsgraph_build.h"
 
+#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 */
@@ -106,6 +113,10 @@ void animviz_free_motionpath_cache(bMotionPath *mpath)
 	/* free the path if necessary */
 	if (mpath->points)
 		MEM_freeN(mpath->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;
@@ -130,6 +141,27 @@ void animviz_free_motionpath(bMotionPath *mpath)
 
 /* ------------------- */
 
+/* Make a copy of motionpath data, so that viewing with copy on write works */
+bMotionPath *animviz_copy_motionpath(const bMotionPath *mpath_src)
+{
+	bMotionPath *mpath_dst;
+
+	if (mpath_src == NULL)
+		return NULL;
+
+	mpath_dst = MEM_dupallocN(mpath_src);
+	mpath_dst->points = MEM_dupallocN(mpath_src->points);
+
+	/* should get recreated on draw... */
+	mpath_dst->points_vbo = NULL;
+	mpath_dst->batch_line = NULL;
+	mpath_dst->batch_points = NULL;
+
+	return mpath_dst;
+}
+
+/* ------------------- */
+
 /**
  * Setup motion paths for the given data.
  * \note Only used when explicitly calculating paths on bones which may/may not be consider already
@@ -212,7 +244,7 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec
 	mpath->color[1] = 0.0;
 	mpath->color[2] = 0.0;
 
-	mpath->line_thickness = 1;
+	mpath->line_thickness = 2;
 	mpath->flag |= MOTIONPATH_FLAG_LINES;  /* draw lines by default */
 
 	/* allocate a cache */
@@ -232,6 +264,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 */
@@ -344,6 +378,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;
+		}
 	}
 }
 
@@ -387,13 +428,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);
 	}
@@ -406,6 +478,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)
@@ -415,6 +488,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/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 3448327586e..c4460d5d909 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1228,7 +1228,8 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_
 	BLI_listbase_clear(&ob_dst->drawdata);
 	BLI_listbase_clear(&ob_dst->pc_ids);
 
-	ob_dst->mpath = NULL;
+	ob_dst->avs = ob_src->avs;
+	ob_dst->mpath = animviz_copy_motionpath(ob_src->mpath);
 
 	copy_object_lod(ob_dst, ob_src, flag_subdata);
 	
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6c2293d2ec1..fedf91669d6 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2965,6 +2965,10 @@ static void direct_link_motionpath(FileData *fd, bMotionPath *mpath)
 	
 	/* relink points cache */
 	mpath->points = newdataadr(fd, mpath->points);
+
+	mpath->points_vbo = NULL;
+	mpath->batch_line = NULL;
+	mpath->batch_points = NULL;
 }
 
 /* ************ READ NODE TREE *************** */
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 0eeb6bae09e..2b6d261d43e 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -53,6 +53,7 @@ set(INC_SYS
 )
 
 set(SRC
+	intern/draw_anim_viz.c
 	intern/draw_armature.c
 	intern/draw_cache.c
 	intern/draw_cache_impl_curve.c
@@ -241,6 +242,9 @@ data_to_c_simple(modes/shaders/common_hair_refine_vert.glsl SRC)
 data_to_c_simple(modes/shaders/common_view_lib.glsl SRC)
 data_to_c_simple(modes/shaders/common_fxaa_lib.glsl SRC)
 data_to_c_simple(modes/shaders/common_fullscreen_vert.glsl SRC)
+data_to_c_simple(modes/shaders/animviz_mpath_lines_vert.glsl SRC)
+data_to_c_simple(modes/shaders/animviz_mpath_lines_geom.glsl SRC)
+data_to_c_simple(modes/shaders/animviz_mpath_points_vert.glsl SRC)
 data_to_c_simple(modes/shaders/armature_axes_vert.glsl SRC)
 data_to_c_simple(modes/shaders/armature_sphere_solid_vert.glsl SRC)
 data_to_c_simple(modes/shaders/armature_sphere_solid_frag.glsl SRC)
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 44fb71a231b..081bae944d8 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -344,6 +344,8 @@ void DRW_shgroup_instance_batch(DRWShadingGroup *shgroup, struct Gwn_Batch *batc
 
 void DRW_shgroup_free(struct DRWShadingGroup *shgroup);
 void DRW_shgroup_call_add(DRWShadingGroup *shgroup, struct Gwn_Batch *geom, float (*obmat)[4]);
+void DRW_shgroup_call_range_add(
+        DRWShadingGroup *shgroup, struct Gwn_Batch *geom, float (*obmat)[4], uint v_sta, uint v_count);
 void DRW_shgroup_call_procedural_points_add(DRWShadingGroup *shgroup, unsigned int point_count, float (*obm

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list