Depsgraph: Cleanup, make code friendlier to be edited in columns

This commit is contained in:
2017-08-22 16:24:58 +02:00
parent c80ab62aee
commit f3e02eb32e

View File

@@ -661,33 +661,46 @@ void DepsgraphRelationBuilder::build_object_parent(Object *ob)
} }
} }
void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode_Type component_type, const char *component_subdata, void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id,
ListBase *constraints, RootPChanMap *root_map) eDepsNode_Type component_type,
const char *component_subdata,
ListBase *constraints,
RootPChanMap *root_map)
{ {
OperationKey constraint_op_key(id, component_type, component_subdata, OperationKey constraint_op_key(
(component_type == DEG_NODE_TYPE_BONE) ? DEG_OPCODE_BONE_CONSTRAINTS : DEG_OPCODE_TRANSFORM_CONSTRAINTS); id,
component_type,
/* add dependencies for each constraint in turn */ component_subdata,
(component_type == DEG_NODE_TYPE_BONE)
? DEG_OPCODE_BONE_CONSTRAINTS
: DEG_OPCODE_TRANSFORM_CONSTRAINTS);
/* Add dependencies for each constraint in turn. */
for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) { for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
/* Invalid constraint type. */
/* invalid constraint type... */ if (cti == NULL) {
if (cti == NULL)
continue; continue;
}
/* special case for camera tracking -- it doesn't use targets to define relations */ /* Special case for camera tracking -- it doesn't use targets to
// TODO: we can now represent dependencies in a much richer manner, so review how this is done... * define relations.
if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) { */
/* TODO: we can now represent dependencies in a much richer manner,
* so review how this is done.
*/
if (ELEM(cti->type,
CONSTRAINT_TYPE_FOLLOWTRACK,
CONSTRAINT_TYPE_CAMERASOLVER,
CONSTRAINT_TYPE_OBJECTSOLVER))
{
bool depends_on_camera = false; bool depends_on_camera = false;
if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) { if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data; bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
if (((data->clip) ||
if (((data->clip) || (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0]) (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0])
{
depends_on_camera = true; depends_on_camera = true;
}
if (data->depth_ob) { if (data->depth_ob) {
// DAG_RL_DATA_OB | DAG_RL_OB_OB
ComponentKey depth_key(&data->depth_ob->id, DEG_NODE_TYPE_TRANSFORM); ComponentKey depth_key(&data->depth_ob->id, DEG_NODE_TYPE_TRANSFORM);
add_relation(depth_key, constraint_op_key, cti->name); add_relation(depth_key, constraint_op_key, cti->name);
} }
@@ -695,24 +708,23 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) { else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
depends_on_camera = true; depends_on_camera = true;
} }
if (depends_on_camera && scene->camera) { if (depends_on_camera && scene->camera) {
// DAG_RL_DATA_OB | DAG_RL_OB_OB
ComponentKey camera_key(&scene->camera->id, DEG_NODE_TYPE_TRANSFORM); ComponentKey camera_key(&scene->camera->id, DEG_NODE_TYPE_TRANSFORM);
add_relation(camera_key, constraint_op_key, cti->name); add_relation(camera_key, constraint_op_key, cti->name);
} }
/* TODO(sergey): This is more a TimeSource -> MovieClip ->
/* TODO(sergey): This is more a TimeSource -> MovieClip -> Constraint dependency chain. */ * Constraint dependency chain.
*/
TimeSourceKey time_src_key; TimeSourceKey time_src_key;
add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]"); add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]");
} }
else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) { else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
/* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint dependency chain. */ /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint
* dependency chain.
*/
TimeSourceKey time_src_key; TimeSourceKey time_src_key;
add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]"); add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]");
bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data; bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data;
if (data->cache_file) { if (data->cache_file) {
ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE); ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE);
add_relation(cache_key, constraint_op_key, cti->name); add_relation(cache_key, constraint_op_key, cti->name);
@@ -721,52 +733,70 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
else if (cti->get_constraint_targets) { else if (cti->get_constraint_targets) {
ListBase targets = {NULL, NULL}; ListBase targets = {NULL, NULL};
cti->get_constraint_targets(con, &targets); cti->get_constraint_targets(con, &targets);
LINKLIST_FOREACH (bConstraintTarget *, ct, &targets) { LINKLIST_FOREACH (bConstraintTarget *, ct, &targets) {
if (ct->tar == NULL) { if (ct->tar == NULL) {
continue; continue;
} }
if (ELEM(con->type,
if (ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK)) { CONSTRAINT_TYPE_KINEMATIC,
/* ignore IK constraints - these are handled separately (on pose level) */ CONSTRAINT_TYPE_SPLINEIK))
{
/* Ignore IK constraints - these are handled separately
* (on pose level).
*/
} }
else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO)) { else if (ELEM(con->type,
/* these constraints require path geometry data... */ CONSTRAINT_TYPE_FOLLOWPATH,
CONSTRAINT_TYPE_CLAMPTO))
{
/* These constraints require path geometry data. */
ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
add_relation(target_key, constraint_op_key, cti->name); // XXX: type = geom_transform add_relation(target_key, constraint_op_key, cti->name);
// TODO: path dependency
} }
else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) { else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) {
/* bone */ /* bone */
if (&ct->tar->id == id) { if (&ct->tar->id == id) {
/* same armature */ /* same armature */
eDepsOperation_Code target_key_opcode; eDepsOperation_Code target_key_opcode;
/* Using "done" here breaks in-chain deps, while using
/* Using "done" here breaks in-chain deps, while using "ready" here breaks most production rigs instead... * "ready" here breaks most production rigs instead.
* So, we do a compromise here, and only do this when an IK chain conflict may occur * So, we do a compromise here, and only do this when an
* IK chain conflict may occur.
*/ */
if (root_map->has_common_root(component_subdata, ct->subtarget)) { if (root_map->has_common_root(component_subdata,
ct->subtarget))
{
target_key_opcode = DEG_OPCODE_BONE_READY; target_key_opcode = DEG_OPCODE_BONE_READY;
} }
else { else {
target_key_opcode = DEG_OPCODE_BONE_DONE; target_key_opcode = DEG_OPCODE_BONE_DONE;
} }
OperationKey target_key(&ct->tar->id,
OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_BONE, ct->subtarget, target_key_opcode); DEG_NODE_TYPE_BONE,
ct->subtarget,
target_key_opcode);
add_relation(target_key, constraint_op_key, cti->name); add_relation(target_key, constraint_op_key, cti->name);
} }
else { else {
/* different armature - we can safely use the result of that */ /* Different armature - we can safely use the result
OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_BONE, ct->subtarget, DEG_OPCODE_BONE_DONE); * of that.
*/
OperationKey target_key(&ct->tar->id,
DEG_NODE_TYPE_BONE,
ct->subtarget,
DEG_OPCODE_BONE_DONE);
add_relation(target_key, constraint_op_key, cti->name); add_relation(target_key, constraint_op_key, cti->name);
} }
} }
else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) { else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) &&
/* vertex group */ (ct->subtarget[0]))
/* NOTE: for now, we don't need to represent vertex groups separately... */ {
/* Vertex group. */
/* NOTE: for now, we don't need to represent vertex groups
* separately.
*/
ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
add_relation(target_key, constraint_op_key, cti->name); add_relation(target_key, constraint_op_key, cti->name);
if (ct->tar->type == OB_MESH) { if (ct->tar->type == OB_MESH) {
OperationDepsNode *node2 = find_operation_node(target_key); OperationDepsNode *node2 = find_operation_node(target_key);
if (node2 != NULL) { if (node2 != NULL) {
@@ -778,37 +808,48 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
/* Constraints which requires the target object surface. */ /* Constraints which requires the target object surface. */
ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
add_relation(target_key, constraint_op_key, cti->name); add_relation(target_key, constraint_op_key, cti->name);
/* NOTE: obdata eval now doesn't necessarily depend on the
/* NOTE: obdata eval now doesn't necessarily depend on the object's transform... */ * object's transform.
ComponentKey target_transform_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM); */
ComponentKey target_transform_key(&ct->tar->id,
DEG_NODE_TYPE_TRANSFORM);
add_relation(target_transform_key, constraint_op_key, cti->name); add_relation(target_transform_key, constraint_op_key, cti->name);
} }
else { else {
/* standard object relation */ /* Standard object relation. */
// TODO: loc vs rot vs scale? // TODO: loc vs rot vs scale?
if (&ct->tar->id == id) { if (&ct->tar->id == id) {
/* Constraint targetting own object: /* Constraint targetting own object:
* - This case is fine IFF we're dealing with a bone constraint pointing to * - This case is fine IFF we're dealing with a bone
* its own armature. In that case, it's just transform -> bone. * constraint pointing to its own armature. In that
* - If however it is a real self targetting case, just make it depend on the * case, it's just transform -> bone.
* previous constraint (or the pre-constraint state)... * - If however it is a real self targetting case, just
* make it depend on the previous constraint (or the
* pre-constraint state).
*/ */
if ((ct->tar->type == OB_ARMATURE) && (component_type == DEG_NODE_TYPE_BONE)) { if ((ct->tar->type == OB_ARMATURE) &&
OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); (component_type == DEG_NODE_TYPE_BONE))
{
OperationKey target_key(&ct->tar->id,
DEG_NODE_TYPE_TRANSFORM,
DEG_OPCODE_TRANSFORM_FINAL);
add_relation(target_key, constraint_op_key, cti->name); add_relation(target_key, constraint_op_key, cti->name);
} }
else { else {
OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); OperationKey target_key(&ct->tar->id,
DEG_NODE_TYPE_TRANSFORM,
DEG_OPCODE_TRANSFORM_LOCAL);
add_relation(target_key, constraint_op_key, cti->name); add_relation(target_key, constraint_op_key, cti->name);
} }
} }
else { else {
/* normal object dependency */ /* Normal object dependency. */
OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); OperationKey target_key(&ct->tar->id,
DEG_NODE_TYPE_TRANSFORM,
DEG_OPCODE_TRANSFORM_FINAL);
add_relation(target_key, constraint_op_key, cti->name); add_relation(target_key, constraint_op_key, cti->name);
} }
} }
/* Constraints which needs world's matrix for transform. /* Constraints which needs world's matrix for transform.
* TODO(sergey): More constraints here? * TODO(sergey): More constraints here?
*/ */
@@ -819,16 +860,16 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
CONSTRAINT_TYPE_TRANSLIKE)) CONSTRAINT_TYPE_TRANSLIKE))
{ {
/* TODO(sergey): Add used space check. */ /* TODO(sergey): Add used space check. */
ComponentKey target_transform_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM); ComponentKey target_transform_key(&ct->tar->id,
DEG_NODE_TYPE_TRANSFORM);
add_relation(target_transform_key, constraint_op_key, cti->name); add_relation(target_transform_key, constraint_op_key, cti->name);
} }
} }
if (cti->flush_constraint_targets) {
if (cti->flush_constraint_targets)
cti->flush_constraint_targets(con, &targets, 1); cti->flush_constraint_targets(con, &targets, 1);
} }
} }
}
} }
void DepsgraphRelationBuilder::build_animdata(ID *id) void DepsgraphRelationBuilder::build_animdata(ID *id)