[Bf-blender-cvs] [98cc417] depsgraph_refactor: Depsgraph: Intial attempt at finishing off hooking up rigidbody sim code to the new depsgraph

Joshua Leung noreply at git.blender.org
Fri Jan 16 05:05:56 CET 2015


Commit: 98cc4176ecb911249ff95d3a9cc8bb72a9423adb
Author: Joshua Leung
Date:   Fri Jan 16 15:06:29 2015 +1300
Branches: depsgraph_refactor
https://developer.blender.org/rB98cc4176ecb911249ff95d3a9cc8bb72a9423adb

Depsgraph: Intial attempt at finishing off hooking up rigidbody sim code to the new depsgraph

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

M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
M	source/blender/depsgraph/intern/depsgraph_build_relations.cpp
M	source/blender/depsgraph/intern/depsnode_opcodes.h

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

diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 1dc9570..cf96a3f 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1618,13 +1618,33 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime) {}
 /* Depsgraph evaluation */
 
 void BKE_rigidbody_rebuild_sim(EvaluationContext *UNUSED(eval_ctx),
-                               Scene *UNUSED(scene))
+                               Scene *scene)
 {
+	float ctime = BKE_scene_frame_get(scene);
+	
+	if (G.debug & G_DEBUG_DEPSGRAPH) {
+		printf("%s at %f\n", __func__, ctime);
+	}
+	
+	/* rebuild sim data (i.e. after resetting to start of timeline) */
+	if (BKE_scene_check_rigidbody_active(scene)) {
+		BKE_rigidbody_rebuild_world(scene, ctime);
+	}
 }
 
 void BKE_rigidbody_eval_simulation(EvaluationContext *UNUSED(eval_ctx),
-                                   Scene *UNUSED(scene))
+                                   Scene *scene)
 {
+	float ctime = BKE_scene_frame_get(scene);
+	
+	if (G.debug & G_DEBUG_DEPSGRAPH) {
+		printf("%s at %f\n", __func__, ctime);
+	}
+	
+	/* evaluate rigidbody sim */
+	if (BKE_scene_check_rigidbody_active(scene)) {
+		BKE_rigidbody_do_simulation(scene, ctime);
+	}
 }
 
 void BKE_rigidbody_object_sync_transforms(EvaluationContext *UNUSED(eval_ctx),
@@ -1633,9 +1653,11 @@ void BKE_rigidbody_object_sync_transforms(EvaluationContext *UNUSED(eval_ctx),
 {
 	RigidBodyWorld *rbw = scene->rigidbody_world;
 	float ctime = BKE_scene_frame_get(scene);
+	
 	if (G.debug & G_DEBUG_DEPSGRAPH) {
 		printf("%s on %s\n", __func__, ob->id.name);
 	}
+	
 	/* read values pushed into RBO from sim/cache... */
 	BKE_rigidbody_sync_transforms(rbw, ob, ctime);
 }
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 06a7d91..98a4cdd 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1805,12 +1805,16 @@ void BKE_scene_update_for_newframe_ex(EvaluationContext *eval_ctx, Main *bmain,
 	 * call this at the start so modifiers with textures don't lag 1 frame */
 	BKE_image_update_frame(bmain, sce->r.cfra);
 	
+#ifdef WITH_LEGACY_DEPSGRAPH
 	/* rebuild rigid body worlds before doing the actual frame update
 	 * this needs to be done on start frame but animation playback usually starts one frame later
 	 * we need to do it here to avoid rebuilding the world on every simulation change, which can be very expensive
 	 */
-	scene_rebuild_rbw_recursive(sce, ctime);
-
+	if (!use_new_eval) {
+		scene_rebuild_rbw_recursive(sce, ctime);
+	}
+#endif
+	
 	sound_set_cfra(sce->r.cfra);
 	
 	/* clear animation overrides */
@@ -1855,8 +1859,12 @@ void BKE_scene_update_for_newframe_ex(EvaluationContext *eval_ctx, Main *bmain,
 
 	/* run rigidbody sim */
 	/* NOTE: current position is so that rigidbody sim affects other objects, might change in the future */
-	scene_do_rb_simulation_recursive(sce, ctime);
-
+#ifdef WITH_LEGACY_DEPSGRAPH
+	if (!use_new_eval) {
+		scene_do_rb_simulation_recursive(sce, ctime);
+	}
+#endif
+	
 	/* BKE_object_handle_update() on all objects, groups and sets */
 #ifdef WITH_LEGACY_DEPSGRAPH
 	if (use_new_eval) {
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
index 3b66e3f..4599f29 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
@@ -349,7 +349,7 @@ void DepsgraphNodeBuilder::build_animdata(ID *id)
 		/* actions and NLA - as a single unit for now, as it gets complicated to schedule otherwise */
 		if ((adt->action) || (adt->nla_tracks.first)) {
 			/* create the node */
-			OperationDepsNode *adt_op;
+			OperationDepsNode *adt_op; // XXX: unread
 			adt_op = add_operation_node(id, DEPSNODE_TYPE_ANIMATION,
 			                            DEPSOP_TYPE_EXEC, function_bind(BKE_animsys_eval_animdata, _1, id, time_src),
 			                            DEG_OPCODE_ANIMATION, id->name);
@@ -437,18 +437,25 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
 	 */
 	
 	/* create nodes ------------------------------------------------------------------------ */
-	/* XXX this needs to be reviewed! */
+	/* XXX: is this the right component, or do we want to use another one instead? */
 	
 	/* init/rebuild operation */
 	/*OperationDepsNode *init_node =*/ add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM,
 	                                                      DEPSOP_TYPE_REBUILD, function_bind(BKE_rigidbody_rebuild_sim, _1, scene),
-	                                                      DEG_OPCODE_PLACEHOLDER, "Rigidbody World Rebuild"); // XXX
+	                                                      DEG_OPCODE_RIGIDBODY_REBUILD);
 	
 	/* do-sim operation */
 	// XXX: what happens if we need to split into several groups?
-	/*OperationDepsNode *sim_node =*/ add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM,
+	OperationDepsNode *sim_node     = add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM,
 	                                                     DEPSOP_TYPE_SIM, function_bind(BKE_rigidbody_eval_simulation, _1, scene),
-	                                                     DEG_OPCODE_PLACEHOLDER, "Rigidbody World Do Simulation"); // XXX
+	                                                     DEG_OPCODE_RIGIDBODY_SIM);
+	
+	/* XXX: For now, the sim node is the only one that really matters here. If any other
+	 * sims get added later, we may have to remove these hacks... 
+	 */
+	sim_node->owner->entry_operation = sim_node;
+	sim_node->owner->exit_operation  = sim_node;
+	
 	
 	/* objects - simulation participants */
 	if (rbw->group) {
@@ -461,7 +468,7 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
 			/* 2) create operation for flushing results */
 			/* object's transform component - where the rigidbody operation lives */
 			add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
-			                   DEPSOP_TYPE_EXEC, function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, ob), /* xxx: function name */
+			                   DEPSOP_TYPE_EXEC, function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, ob),
 			                   DEG_OPCODE_TRANSFORM_RIGIDBODY);
 		}
 	}
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index 292f895..6c62d6a 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -256,6 +256,11 @@ void DepsgraphRelationBuilder::build_scene(Scene *scene)
 		}
 	}
 #endif
+
+	/* rigidbody */
+	if (scene->rigidbody_world) {
+		build_rigidbody(scene);
+	}
 	
 	/* scene's animation and drivers */
 	if (scene->adt) {
@@ -793,8 +798,8 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
 {
 	RigidBodyWorld *rbw = scene->rigidbody_world;
 	
-	OperationKey init_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_PLACEHOLDER, "Rigidbody World Rebuild"); // XXX
-	OperationKey sim_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_PLACEHOLDER, "Rigidbody World Do Simulation"); // XXX
+	OperationKey init_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD);
+	OperationKey sim_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM);
 	
 	/* rel between the two sim-nodes */
 	add_relation(init_key, sim_key, DEPSREL_TYPE_OPERATION, "Rigidbody [Init -> SimStep]");
diff --git a/source/blender/depsgraph/intern/depsnode_opcodes.h b/source/blender/depsgraph/intern/depsnode_opcodes.h
index 0dd2b6c..b7d5334 100644
--- a/source/blender/depsgraph/intern/depsnode_opcodes.h
+++ b/source/blender/depsgraph/intern/depsnode_opcodes.h
@@ -75,7 +75,11 @@ DEF_DEG_OPCODE(TRANSFORM_CONSTRAINTS)
 //DEF_DEG_OPCODE(TRANSFORM_CONSTRAINT)
 //DEF_DEG_OPCODE(TRANSFORM_CONSTRAINTS_DONE)
 
-/* Rigidbody Sim - Copy Results */
+/* Rigidbody Sim - Perform Sim */
+DEF_DEG_OPCODE(RIGIDBODY_REBUILD)
+DEF_DEG_OPCODE(RIGIDBODY_SIM)
+
+/* Rigidbody Sim - Copy Results to Object */
 DEF_DEG_OPCODE(TRANSFORM_RIGIDBODY)
 
 /* Transform exitpoint */




More information about the Bf-blender-cvs mailing list