[Bf-blender-cvs] [3330e46] depsgraph_refactor: Depsgraph: Hook up constraints evaluation callback

Sergey Sharybin noreply at git.blender.org
Fri Nov 7 14:35:23 CET 2014


Commit: 3330e4676c639a200b8d2212f6dd539c56cc141d
Author: Sergey Sharybin
Date:   Fri Nov 7 14:13:04 2014 +0100
Branches: depsgraph_refactor
https://developer.blender.org/rB3330e4676c639a200b8d2212f6dd539c56cc141d

Depsgraph: Hook up constraints evaluation callback

Quite straightforward. There's one extra flag to the old object where_is
which helps preventing duplicated code needed for old dependency graph
system In the future we'll get rid of this argument and decouple all the
functions in a nice way.

One retarded issue is setting negative scale flag on the object, which
currently happens in both local transform and constraints update.

Bigger issue here is the original object matrix which should be used
as an input for the constraints stack. Currently constraints will operate
on the previous final object matrix when changing the dependencies of the
constraint list.

This is possible to solve by storing intermediate data in the graph
(or somewhere else(, but for until that's nicely implemented we'll probably
couple constraints back. Will investigate this further.

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

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/object_update.c
M	source/blender/depsgraph/intern/depsgraph_build.h
M	source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
M	source/blender/depsgraph/intern/depsgraph_build_relations.cpp
M	source/blender/depsgraph/intern/depsgraph_type_defines.cpp
M	source/blender/depsgraph/intern/stubs.h

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

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 752f480..e4f1d3c 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -120,7 +120,8 @@ void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob);
 void BKE_object_where_is_calc_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, float r_originmat[3][3]);
 void BKE_object_where_is_calc_time(struct Scene *scene, struct Object *ob, float ctime);
 void BKE_object_where_is_calc_time_ex(struct Scene *scene, struct Object *ob, float ctime,
-                                      struct RigidBodyWorld *rbw, float r_originmat[3][3]);
+                                      struct RigidBodyWorld *rbw, float r_originmat[3][3],
+                                      bool do_constraints);
 void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]);
 
 /* possibly belong in own moduke? */
@@ -173,6 +174,9 @@ void BKE_object_tfm_protected_restore(struct Object *ob,
 void BKE_object_eval_local_transform(struct EvaluationContext *eval_ctx,
                                      struct Scene *scene,
                                      struct Object *ob);
+void BKE_object_constraints_evaluate(struct EvaluationContext *eval_ctx,
+                                     struct Scene *scene,
+                                     struct Object *ob);
 void BKE_object_eval_geometry(struct EvaluationContext *eval_ctx,
                               struct Scene *scene,
                               struct Object *ob);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 3e9aa68..97133ae 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2413,8 +2413,12 @@ static bool where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat
 }
 
 /* note, scene is the active scene while actual_scene is the scene the object resides in */
+/* TODO(sergey): Extra do_constraints flag here is just to prevent code duplication for
+ * the time being we don't kick old depsgraph out.
+ */
 void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
-                                      RigidBodyWorld *rbw, float r_originmat[3][3])
+                                      RigidBodyWorld *rbw, float r_originmat[3][3],
+                                      bool do_constraints)
 {
 	if (ob == NULL) return;
 	
@@ -2446,7 +2450,7 @@ void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
 	BKE_rigidbody_sync_transforms(rbw, ob, ctime);
 	
 	/* solve constraints */
-	if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
+	if (do_constraints && ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
 		bConstraintOb *cob;
 		cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
 		BKE_constraints_solve(&ob->constraints, cob, ctime);
@@ -2460,7 +2464,7 @@ void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
 
 void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
 {
-	BKE_object_where_is_calc_time_ex(scene, ob, ctime, NULL, NULL);
+	BKE_object_where_is_calc_time_ex(scene, ob, ctime, NULL, NULL, true);
 }
 
 /* get object transformation matrix without recalculating dependencies and
@@ -2487,11 +2491,11 @@ void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4])
 
 void BKE_object_where_is_calc_ex(Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
 {
-	BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), rbw, r_originmat);
+	BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), rbw, r_originmat, true);
 }
 void BKE_object_where_is_calc(Scene *scene, Object *ob)
 {
-	BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), NULL, NULL);
+	BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), NULL, NULL, true);
 }
 
 /* for calculation of the inverse parent transform, only used for editor */
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index b8fd0a5..1be00b6 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -40,6 +40,7 @@
 #include "BKE_global.h"
 #include "BKE_armature.h"
 #include "BKE_action.h"
+#include "BKE_constraint.h"
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_animsys.h"
@@ -57,12 +58,33 @@
 
 #include "DEG_depsgraph.h"
 
+#define PRINT if (DEG_get_eval_mode() == DEG_EVAL_MODE_NEW) printf
+
 void BKE_object_eval_local_transform(EvaluationContext *UNUSED(eval_ctx),
                                      Scene *scene,
                                      Object *ob)
 {
-	printf("%s on %s\n", __func__, ob->id.name);
-	BKE_object_where_is_calc_ex(scene, NULL, ob, NULL);
+	float ctime = BKE_scene_frame_get(scene);
+	PRINT("%s on %s\n", __func__, ob->id.name);
+	BKE_object_where_is_calc_time_ex(scene, ob, ctime, scene->rigidbody_world, NULL, false);
+}
+
+void BKE_object_constraints_evaluate(EvaluationContext *eval_ctx,
+                                     Scene *scene,
+                                     Object *ob)
+{
+	float ctime = BKE_scene_frame_get(scene);
+	(void) eval_ctx;  /* Ignored. */
+
+	PRINT("%s on %s\n", __func__, ob->id.name);
+
+	/* solve constraints */
+	if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
+		bConstraintOb *cob;
+		cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
+		BKE_constraints_solve(&ob->constraints, cob, ctime);
+		BKE_constraints_clear_evalob(cob);
+	}
 }
 
 void BKE_object_eval_geometry(EvaluationContext *eval_ctx,
@@ -74,9 +96,7 @@ void BKE_object_eval_geometry(EvaluationContext *eval_ctx,
 	Key *key;
 	float ctime = BKE_scene_frame_get(scene);
 
-	if (DEG_get_eval_mode() == DEG_EVAL_MODE_NEW) {
-		printf("%s on %s\n", __func__, ob->id.name);
-	}
+	PRINT("%s on %s\n", __func__, ob->id.name);
 
 	if (G.debug & G_DEBUG_DEPSGRAPH)
 		printf("recalcdata %s\n", ob->id.name + 2);
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index 52f5df1..3049d2f 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -129,7 +129,7 @@ struct DepsgraphNodeBuilder {
 	void build_group(Group *group);
 	void build_object(Scene *scene, Object *ob);
 	void build_object_transform(Scene *scene, Object *ob);
-	void build_object_constraints(Object *ob);
+	void build_object_constraints(Scene *scene, Object *ob);
 	void build_pose_constraints(Object *ob, bPoseChannel *pchan);
 	void build_rigidbody(Scene *scene);
 	void build_particles(Object *ob);
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
index 62f8de7..ff0b9b3 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
@@ -229,7 +229,7 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, Object *ob)
 	
 	/* object constraints */
 	if (ob->constraints.first) {
-		build_object_constraints(ob);
+		build_object_constraints(scene, ob);
 	}
 	
 	/* object data */
@@ -299,11 +299,11 @@ void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob)
  *
  * -- Aligorith, August 2013 
  */
-void DepsgraphNodeBuilder::build_object_constraints(Object *ob)
+void DepsgraphNodeBuilder::build_object_constraints(Scene *scene, Object *ob)
 {
 	/* create node for constraint stack */
 	add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
-	                   DEPSOP_TYPE_EXEC, bind(BKE_object_constraints_evaluate, _1, ob),
+	                   DEPSOP_TYPE_EXEC, bind(BKE_object_constraints_evaluate, _1, scene, ob),
 	                   deg_op_name_constraint_stack);
 }
 
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index 0f38b4d..e777423 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -406,6 +406,12 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
 						//node2->customdata_mask |= CD_MASK_MDEFORMVERT;
 					}
 				}
+				else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
+					/* Constraints which requires the target object surface. */
+					/* TODO(sergey): More cosntarints here? */
+					ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY);
+					add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
+				}
 				else {
 					/* standard object relation */
 					// TODO: loc vs rot vs scale?
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
index 083ce0c..77ad25f 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
@@ -64,7 +64,6 @@ extern "C" {
 
 void BKE_animsys_eval_driver(EvaluationContext *eval_ctx, ID *id, FCurve *fcurve) {}
 
-void BKE_object_constraints_evaluate(EvaluationContext *eval_ctx, Object *ob) {}
 void BKE_pose_constraints_evaluate(EvaluationContext *eval_ctx, Object *ob, bPoseChannel *pchan) {}
 
 void BKE_pose_iktree_evaluate(EvaluationContext *eval_ctx, Object *ob, bPoseChannel *rootchan) {}
diff --git a/source/blender/depsgraph/intern/stubs.h b/source/blender/depsgraph/intern/stubs.h
index 8609fa3..178f9ea 100644
--- a/source/blender/depsgraph/intern/stubs.h
+++ b/source/blender/depsgraph/intern/stubs.h
@@ -26,7 +26,6 @@ struct EvaluationContext;
 
 void BKE_animsys_eval_driver(struct EvaluationContext *eval_ctx, ID *id, FCurve *fcurve);
 
-void BKE_object_constraints_evaluate(struct EvaluationContext *eval_ctx, Object *ob);
 void BKE_pose_constraints_evaluate(struct EvaluationContext *eval_ctx, Object *ob, bPoseChannel *pchan);
 
 void B

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list