[Bf-blender-cvs] [86eecd9] depsgraph_refactor: Ported over build functions for rigidbody nodes/relations.

Lukas Tönne noreply at git.blender.org
Thu Apr 10 09:18:32 CEST 2014


Commit: 86eecd945fa6ff5132832e74caca6e272b89fe9a
Author: Lukas Tönne
Date:   Thu Apr 10 09:12:28 2014 +0200
https://developer.blender.org/rB86eecd945fa6ff5132832e74caca6e272b89fe9a

Ported over build functions for rigidbody nodes/relations.

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

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/depsgraph_types.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index c483d8d..020ccb3 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -71,7 +71,7 @@ struct DepsgraphNodeBuilder {
 	IDDepsNode *build_object(Object *ob);
 	ComponentDepsNode *build_object_transform(Object *ob, IDDepsNode *ob_node);
 	void build_constraints(ComponentDepsNode *comp_node, eDepsNode_Type constraint_op_type);
-	void build_rigidbody(Scene *scene);
+	void build_rigidbody(IDDepsNode *scene_node, Scene *scene);
 	void build_animdata(IDDepsNode *id_node);
 	OperationDepsNode *build_driver(ComponentDepsNode *adt_node, FCurve *fcurve);
 	void build_nodetree(DepsNode *owner_node, bNodeTree *ntree);
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
index 7059b25..cea443e 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
@@ -152,7 +152,7 @@ IDDepsNode *DepsgraphNodeBuilder::build_scene(Scene *scene)
 	
 	/* rigidbody */
 	if (scene->rigidbody_world) {
-		build_rigidbody(scene);
+		build_rigidbody(scene_node, scene);
 	}
 	
 	/* scene's animation and drivers */
@@ -197,7 +197,7 @@ IDDepsNode *DepsgraphNodeBuilder::build_object(Object *ob)
 	if (ob->parent) {
 		add_operation_node(trans_node, DEPSNODE_TYPE_OP_TRANSFORM, 
 		                   DEPSOP_TYPE_EXEC, BKE_object_eval_parent,
-		                   "BKE_object_eval_parent", make_rna_id_pointer(ob));
+		                   deg_op_name_object_parent, make_rna_id_pointer(ob));
 	}
 	
 	/* object constraints */
@@ -265,7 +265,7 @@ ComponentDepsNode *DepsgraphNodeBuilder::build_object_transform(Object *ob, IDDe
 	/* init operation */
 	add_operation_node(trans_node, DEPSNODE_TYPE_OP_TRANSFORM,
 	                   DEPSOP_TYPE_INIT, BKE_object_eval_local_transform,
-	                   "BKE_object_eval_local_transform", make_rna_id_pointer(ob));
+	                   deg_op_name_object_local_transform, make_rna_id_pointer(ob));
 	
 	/* return component created */
 	return trans_node;
@@ -295,11 +295,6 @@ void DepsgraphNodeBuilder::build_constraints(ComponentDepsNode *comp_node, eDeps
 	                   deg_op_name_constraint_stack, make_rna_id_pointer(comp_node->owner->id));
 }
 
-void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
-{
-	
-}
-
 /* Build graph nodes for AnimData block 
  * < scene_node: Scene that ID-block this lives on belongs to
  * < id: ID-Block which hosts the AnimData
@@ -381,6 +376,63 @@ void DepsgraphNodeBuilder::build_world(World *world)
 	id_tag_clear(world);
 }
 
+/* Rigidbody Simulation - Scene Level */
+void DepsgraphNodeBuilder::build_rigidbody(IDDepsNode *scene_node, Scene *scene)
+{
+	RigidBodyWorld *rbw = scene->rigidbody_world;
+	OperationDepsNode *init_node;
+	OperationDepsNode *sim_node; // XXX: what happens if we need to split into several groups?
+	
+	/* == Rigidbody Simulation Nodes == 
+	 * There are 3 nodes related to Rigidbody Simulation:
+	 * 1) "Initialise/Rebuild World" - this is called sparingly, only when the simulation
+	 *    needs to be rebuilt (mainly after file reload, or moving back to start frame)
+	 * 2) "Do Simulation" - perform a simulation step - interleaved between the evaluation
+	 *    steps for clusters of objects (i.e. between those affected and/or not affected by
+	 *    the sim for instance)
+	 *
+	 * 3) "Pull Results" - grab the specific transforms applied for a specific object -
+	 *    performed as part of object's transform-stack building
+	 */
+	
+	/* create nodes ------------------------------------------------------------------------ */
+	/* XXX this needs to be reviewed! */
+	ComponentDepsNode *scene_trans = scene_node->find_component(DEPSNODE_TYPE_TRANSFORM);
+	
+	/* init/rebuild operation */
+	init_node = add_operation_node(scene_trans, DEPSNODE_TYPE_OP_RIGIDBODY,
+	                               DEPSOP_TYPE_REBUILD, BKE_rigidbody_rebuild_sim,
+	                               deg_op_name_rigidbody_world_rebuild, PointerRNA_NULL);
+	
+	/* do-sim operation */
+	sim_node = add_operation_node(scene_trans, DEPSNODE_TYPE_OP_RIGIDBODY,
+	                              DEPSOP_TYPE_SIM, BKE_rigidbody_eval_simulation,
+	                              deg_op_name_rigidbody_world_simulate, PointerRNA_NULL);
+	
+	/* objects - simulation participants */
+	if (rbw->group) {
+		for (GroupObject *go = (GroupObject *)rbw->group->gobject.first; go; go = go->next) {
+			Object *ob = go->ob;
+			
+			if (!ob || ob->type != OB_MESH)
+				continue;
+			
+			/* object's transform component - where the rigidbody operation lives
+			 * NOTE: since we're doing this step after all objects have been built,
+			 *       we can safely assume that all necessary ops we have to play with
+			 *       already exist
+			 */
+			IDDepsNode *ob_node = m_graph->find_id_node(&ob->id);
+			ComponentDepsNode *tcomp = ob_node->find_component(DEPSNODE_TYPE_TRANSFORM);
+			
+			/* 2) create operation for flushing results */
+			add_operation_node(tcomp, DEPSNODE_TYPE_OP_TRANSFORM,
+			                   DEPSOP_TYPE_EXEC, BKE_rigidbody_object_sync_transforms, /* xxx: function name */
+			                   deg_op_name_rigidbody_object_sync, PointerRNA_NULL);
+		}
+	}
+}
+
 void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree)
 {
 	if (!ntree)
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index dee1ccc..cbee3a3 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -367,7 +367,76 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, IDPtr id, eDepsNo
 
 void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
 {
+	RigidBodyWorld *rbw = scene->rigidbody_world;
 	
+	OperationKey init_key(scene, DEPSNODE_TYPE_OP_RIGIDBODY, deg_op_name_rigidbody_world_rebuild);
+	OperationKey sim_key(scene, DEPSNODE_TYPE_OP_RIGIDBODY, deg_op_name_rigidbody_world_simulate);
+	
+	/* rel between the two sim-nodes */
+	add_relation(init_key, sim_key, DEPSREL_TYPE_OPERATION, "Rigidbody [Init -> SimStep]");
+	
+	/* set up dependencies between these operations and other builtin nodes --------------- */	
+	
+	/* time dependency */
+	TimeSourceKey time_src_key;
+	add_relation(time_src_key, init_key, DEPSREL_TYPE_TIME, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)");
+	add_relation(time_src_key, sim_key, DEPSREL_TYPE_TIME, "TimeSrc -> Rigidbody Sim Step");
+	
+	/* objects - simulation participants */
+	if (rbw->group) {
+		for (GroupObject *go = (GroupObject *)rbw->group->gobject.first; go; go = go->next) {
+			Object *ob = go->ob;
+			if (!ob || ob->type != OB_MESH)
+				continue;
+			
+			/* hook up evaluation order... 
+			 * 1) flushing rigidbody results follows base transforms being applied
+			 * 2) rigidbody flushing can only be performed after simulation has been run
+			 *
+			 * 3) simulation needs to know base transforms to figure out what to do
+			 *    XXX: there's probably a difference between passive and active 
+			 *         - passive don't change, so may need to know full transform...
+			 */
+			OperationKey rbo_key(ob, DEPSNODE_TYPE_OP_TRANSFORM, deg_op_name_rigidbody_object_sync);
+			
+			const string &trans_op_name = ob->parent ? deg_op_name_object_parent : deg_op_name_object_local_transform;
+			OperationKey trans_op(ob, DEPSNODE_TYPE_OP_TRANSFORM, trans_op_name);
+			
+			add_relation(trans_op, rbo_key, DEPSREL_TYPE_OPERATION, "Base Ob Transform -> RBO Sync");
+			add_relation(sim_key, rbo_key, DEPSREL_TYPE_COMPONENT_ORDER, "Rigidbody Sim Eval -> RBO Sync");
+			
+			OperationKey constraint_key(ob, DEPSNODE_TYPE_OP_TRANSFORM, deg_op_name_constraint_stack);
+			add_relation(rbo_key, constraint_key, DEPSREL_TYPE_COMPONENT_ORDER, "RBO Sync -> Ob Constraints");
+			
+			/* needed to get correct base values */
+			add_relation(trans_op, sim_key, DEPSREL_TYPE_OPERATION, "Base Ob Transform -> Rigidbody Sim Eval");
+		}
+	}
+	
+	/* constraints */
+	if (rbw->constraints) {
+		for (GroupObject *go = (GroupObject *)rbw->constraints->gobject.first; go; go = go->next) {
+			Object *ob = go->ob;
+			if (!ob || !ob->rigidbody_constraint)
+				continue;
+			
+			RigidBodyCon *rbc = ob->rigidbody_constraint;
+			
+			/* final result of the constraint object's transform controls how the
+			 * constraint affects the physics sim for these objects 
+			 */
+			ComponentKey trans_key(ob, DEPSNODE_TYPE_TRANSFORM);
+			OperationKey ob1_key(rbc->ob1, DEPSNODE_TYPE_OP_TRANSFORM, deg_op_name_rigidbody_object_sync);
+			OperationKey ob2_key(rbc->ob2, DEPSNODE_TYPE_OP_TRANSFORM, deg_op_name_rigidbody_object_sync);
+			
+			/* - constrained-objects sync depends on the constraint-holder */
+			add_relation(trans_key, ob1_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_1");
+			add_relation(trans_key, ob2_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_2");
+			
+			/* - ensure that sim depends on this constraint's transform */
+			add_relation(trans_key, sim_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint Transform -> RB Simulation");
+		}
+	}
 }
 
 void DepsgraphRelationBuilder::build_animdata(IDPtr id)
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
index 24144a6..0370ede 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
@@ -86,7 +86,12 @@ void BKE_curve_eval_geometry(void *context, void *item) {}
 void BKE_curve_eval_path(void *context, void *item) {}
 void BKE_lattice_eval_geometry(void *context, void *item) {}
 
+const string deg_op_name_object_parent = "BKE_object_eval_parent";
+const string deg_op_name_object_local_transform = "BKE_object_eval_local_transform";
 const string deg_op_name_constraint_stack = "Constraint Stack";
+const string deg_op_name_rigidbody_world_rebuild = "Rigidbody World Rebuild";
+const strin

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list