[Bf-blender-cvs] [57abe7b1327] tmp-COW_InsertKeyframe_Fix: WIP COW Fix: Insert keyframe operators/api now queries depsgraph for evaluated data

Joshua Leung noreply at git.blender.org
Fri May 18 20:36:52 CEST 2018


Commit: 57abe7b1327fc67bd23d4d9ae16c77160fc2e0e8
Author: Joshua Leung
Date:   Fri May 18 20:36:48 2018 +0200
Branches: tmp-COW_InsertKeyframe_Fix
https://developer.blender.org/rB57abe7b1327fc67bd23d4d9ae16c77160fc2e0e8

WIP COW Fix:  Insert keyframe operators/api now queries depsgraph for evaluated data

When using copy on write, insert keyframe operators were reading from old
bmain data instead of COW data. This meant that inserting keyframes would
often read old/stale data, resulting in invalid keyframes getting created
(e.g. from last transform operation, instead of actual current state).

This commit makes it so that keyframing operators will ask depsgraph for
the evaluated copy of the data, so that it can read values from that. It
introduces a new function - `DEG_get_evaluated_rna_pointer()`, which when
working correctly/fully, should work just like the other `DEG_get_evaluated_*()`
functions, except it lets you pass in an RNA Pointer.

However, currently, this is only done for Pose Bones (as a dirty hack, since this
is an important/pivotal requirement for production) and/or datablock
properties directly (since we can just use the DEG_get_evaluated_id() directly).
on the datablock.

Committing to a branch for now as this all needs more testing. More work to come
later at a more sane time of day!

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

M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/depsgraph_query.cc
M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/animation/anim_filter.c
M	source/blender/editors/animation/keyframing.c
M	source/blender/editors/animation/keyingsets.c
M	source/blender/editors/armature/pose_utils.c
M	source/blender/editors/gpencil/gpencil_convert.c
M	source/blender/editors/include/ED_anim_api.h
M	source/blender/editors/include/ED_keyframing.h
M	source/blender/editors/interface/interface_anim.c
M	source/blender/editors/space_action/action_edit.c
M	source/blender/editors/space_graph/graph_edit.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/python/intern/bpy_rna_anim.c

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

diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index 6d21c143877..e77bf62bab6 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -85,6 +85,10 @@ struct Object *DEG_get_evaluated_object(const struct Depsgraph *depsgraph,
 struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph,
                                 struct ID *id);
 
+/* Get evaluated version of data pointed to by RNA pointer */
+void DEG_get_evaluated_rna_pointer(const struct Depsgraph *depsgraph,
+                                   const struct PointerRNA *ptr,
+                                   struct PointerRNA *r_ptr_eval);
 
 /* Get original version of object for given evaluated one. */
 struct Object *DEG_get_original_object(struct Object *object);
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc
index fea28736627..167e9e0e7d2 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -33,15 +33,21 @@
 #include "MEM_guardedalloc.h"
 
 extern "C" {
+#include <string.h> // XXX: memcpy
+
 #include "BLI_utildefines.h"
 #include "BKE_idcode.h"
 #include "BKE_main.h"
 #include "BLI_listbase.h"
+
+#include "BKE_action.h" // XXX: BKE_pose_channel_from_name
 } /* extern "C" */
 
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
+#include "RNA_access.h"
+
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 
@@ -152,6 +158,39 @@ ID *DEG_get_evaluated_id(const Depsgraph *depsgraph, ID *id)
 	return id_node->id_cow;
 }
 
+/* Get evaluated version of data pointed to by RNA pointer */
+void DEG_get_evaluated_rna_pointer(const Depsgraph *depsgraph, const PointerRNA *ptr, PointerRNA *r_ptr_eval)
+{
+	if ((ptr == NULL) || (r_ptr_eval == NULL)) {
+		return;
+	}
+	if ((ptr->id.data == ptr->data)) {
+		ID *orig_id = (ID *)ptr->id.data;
+		ID *cow_id = DEG_get_evaluated_id(depsgraph, orig_id);
+		/* For ID pointers, it's easy... */
+		r_ptr_eval->id.data = (void *)cow_id;
+		r_ptr_eval->data = (void *)cow_id;
+		r_ptr_eval->type = ptr->type;
+	}
+	else {
+		/* XXX: Hack for common cases... Proper fix needs to be made still... A very tricky problem though! */
+		if (ptr->type == &RNA_PoseBone) {
+			const Object *ob_eval = (Object *)DEG_get_evaluated_id(depsgraph, (ID *)ptr->id.data);
+			bPoseChannel *pchan = (bPoseChannel *)ptr->data;
+			const bPoseChannel *pchan_eval = BKE_pose_channel_find_name(ob_eval->pose, pchan->name);
+			/* XXX: Hack - This is just temporary... but this case must be supported. */
+			r_ptr_eval->id.data = (void *)&ob_eval->id;
+			r_ptr_eval->data = (void *)pchan_eval;
+			r_ptr_eval->type = ptr->type;
+		}
+		else {
+			/* FIXME: Maybe we should try resolving paths, or using some kind of depsgraph lookup? */
+			// XXX: For now, just use dirty hack, and hope it doesn't cause nasty issues.
+			*r_ptr_eval = *ptr;
+		}
+	}
+}
+
 Object *DEG_get_original_object(Object *object)
 {
 	return (Object *)DEG_get_original_id(&object->id);
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index c8d606db229..e0bb9eebffb 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -70,6 +70,8 @@
 
 #include "GPU_immediate.h"
 
+#include "DEG_depsgraph.h"
+
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
 #include "UI_resources.h"
@@ -4097,6 +4099,7 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi
 	AnimData *adt = BKE_animdata_from_id(id);
 	FCurve *fcu = (FCurve *)fcu_poin;
 	
+	Depsgraph *depsgraph = CTX_data_depsgraph(C);
 	ReportList *reports = CTX_wm_reports(C);
 	Scene *scene = CTX_data_scene(C);
 	ToolSettings *ts = scene->toolsettings;
@@ -4122,7 +4125,7 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi
 			flag |= INSERTKEY_REPLACE;
 		
 		/* insert a keyframe for this F-Curve */
-		done = insert_keyframe_direct(reports, ptr, prop, fcu, cfra, ts->keyframe_type, flag);
+		done = insert_keyframe_direct(depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, flag);
 		
 		if (done)
 			WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
@@ -4136,6 +4139,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi
 	KeyBlock *kb = (KeyBlock *)kb_poin;
 	char *rna_path = BKE_keyblock_curval_rnapath_get(key, kb);
 	
+	Depsgraph *depsgraph = CTX_data_depsgraph(C);
 	ReportList *reports = CTX_wm_reports(C);
 	Scene *scene = CTX_data_scene(C);
 	ToolSettings *ts = scene->toolsettings;
@@ -4166,7 +4170,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi
 			flag |= INSERTKEY_REPLACE;
 		
 		/* insert a keyframe for this F-Curve */
-		done = insert_keyframe_direct(reports, ptr, prop, fcu, cfra, ts->keyframe_type, flag);
+		done = insert_keyframe_direct(depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, flag);
 		
 		if (done)
 			WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
@@ -4187,6 +4191,7 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, void *UNUSED(id_po
 	PropertyRNA *prop;
 	int index;
 	
+	Depsgraph *depsgraph = CTX_data_depsgraph(C);
 	ReportList *reports = CTX_wm_reports(C);
 	Scene *scene = CTX_data_scene(C);
 	ToolSettings *ts = scene->toolsettings;
@@ -4209,7 +4214,7 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, void *UNUSED(id_po
 			flag |= INSERTKEY_REPLACE;
 		
 		/* insert a keyframe for this F-Curve */
-		done = insert_keyframe_direct(reports, ptr, prop, fcu, cfra, ts->keyframe_type, flag);
+		done = insert_keyframe_direct(depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, flag);
 		
 		if (done)
 			WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c
index aad4f71fe9a..d8dc4af52f3 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -392,6 +392,7 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
 	if (scene) {
 		ac->markers = ED_context_get_markers(C);
 	}
+	ac->depsgraph = CTX_data_depsgraph(C);
 	ac->view_layer = CTX_data_view_layer(C);
 	ac->obact = (ac->view_layer->basact) ? ac->view_layer->basact->object : NULL;
 	ac->sa = sa;
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 7b637e5b725..67f5aef2517 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -67,6 +67,7 @@
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
 
 #include "ED_anim_api.h"
 #include "ED_keyframing.h"
@@ -615,31 +616,34 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue)
 /* ------------------ RNA Data-Access Functions ------------------ */
 
 /* Try to read value using RNA-properties obtained already */
-static float setting_get_rna_value(PointerRNA *ptr, PropertyRNA *prop, int index)
+static float setting_get_rna_value(Depsgraph *depsgraph, PointerRNA *ptr, PropertyRNA *prop, int index)
 {
+	PointerRNA ptr_eval;
 	float value = 0.0f;
 	
+	DEG_get_evaluated_rna_pointer(depsgraph, ptr, &ptr_eval);
+	
 	switch (RNA_property_type(prop)) {
 		case PROP_BOOLEAN:
 			if (RNA_property_array_check(prop))
-				value = (float)RNA_property_boolean_get_index(ptr, prop, index);
+				value = (float)RNA_property_boolean_get_index(&ptr_eval, prop, index);
 			else
-				value = (float)RNA_property_boolean_get(ptr, prop);
+				value = (float)RNA_property_boolean_get(&ptr_eval, prop);
 			break;
 		case PROP_INT:
 			if (RNA_property_array_check(prop))
-				value = (float)RNA_property_int_get_index(ptr, prop, index);
+				value = (float)RNA_property_int_get_index(&ptr_eval, prop, index);
 			else
-				value = (float)RNA_property_int_get(ptr, prop);
+				value = (float)RNA_property_int_get(&ptr_eval, prop);
 			break;
 		case PROP_FLOAT:
 			if (RNA_property_array_check(prop))
-				value = RNA_property_float_get_index(ptr, prop, index);
+				value = RNA_property_float_get_index(&ptr_eval, prop, index);
 			else
-				value = RNA_property_float_get(ptr, prop);
+				value = RNA_property_float_get(&ptr_eval, prop);
 			break;
 		case PROP_ENUM:
-			value = (float)RNA_property_enum_get(ptr, prop);
+			value = (float)RNA_property_enum_get(&ptr_eval, prop);
 			break;
 		default:
 			break;
@@ -800,7 +804,7 @@ static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop)
  * In the event that it is not possible to perform visual keying, try to fall-back
  * to using the default method. Assumes that all data it has been passed is valid.
  */
-static float visualkey_get_value(PointerRNA *ptr, PropertyRNA *prop, int array_index)
+static float visualkey_get_value(Depsgraph *depsgraph, PointerRNA *ptr, PropertyRNA *prop, int array_index)
 {
 	const char *identifier = RNA_property_identifier(prop);
 	float tmat[4][4];
@@ -815,20 +819,25 @@ static float visualkey_get_value(PointerRNA *ptr, PropertyRNA *prop, int array_i
 	 */
 	if (ptr->type == &RNA_Object) {
 		Object *ob = (Object *)ptr->data;
+		const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
 		
 		/* Loc code is specific... */
 		if (strstr(identifier, "location")) {
-			return ob->obmat[3][array_index];
+			return ob_eval->obmat[3][array_index];
 		}
 		
-		copy_m4_m4(tmat, ob->obmat);
-		rotmode = ob->rotmode;
+		copy_m4_m4(tmat, ob_eval->obmat);
+		rotmode = ob_eval->rotmode;
 	}
 	else if (ptr->type == &RNA_PoseBone) {
+		Object *ob = (Object *)ptr->id.data;
 		bPoseChannel *pchan = (bPoseChannel *)ptr->data;
 		
-		BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, tmat);
-		rotmode = pchan->rotmode;
+		const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+		bPoseChannel *pchan_eval = BKE_pose_channel_find_name(ob_eval->pose, pchan->name);
+		
+		BK

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list