2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2013 Blender Foundation.
19 * All rights reserved.
21 * Original Author: Joshua Leung
22 * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/depsgraph/intern/builder/deg_build_nodes.cc
30 * Methods for constructing depsgraph's nodes
33 #include "intern/builder/deg_builder_nodes.h"
39 #include "MEM_guardedalloc.h"
42 #include "BLI_blenlib.h"
43 #include "BLI_string.h"
44 #include "BLI_utildefines.h"
46 #include "DNA_action_types.h"
47 #include "DNA_anim_types.h"
48 #include "DNA_armature_types.h"
49 #include "DNA_camera_types.h"
50 #include "DNA_constraint_types.h"
51 #include "DNA_curve_types.h"
52 #include "DNA_effect_types.h"
53 #include "DNA_gpencil_types.h"
54 #include "DNA_group_types.h"
55 #include "DNA_key_types.h"
56 #include "DNA_lamp_types.h"
57 #include "DNA_material_types.h"
58 #include "DNA_mesh_types.h"
59 #include "DNA_meta_types.h"
60 #include "DNA_node_types.h"
61 #include "DNA_object_types.h"
62 #include "DNA_rigidbody_types.h"
63 #include "DNA_scene_types.h"
64 #include "DNA_texture_types.h"
65 #include "DNA_world_types.h"
67 #include "BKE_action.h"
68 #include "BKE_armature.h"
69 #include "BKE_animsys.h"
70 #include "BKE_constraint.h"
71 #include "BKE_curve.h"
72 #include "BKE_depsgraph.h"
73 #include "BKE_effect.h"
74 #include "BKE_fcurve.h"
75 #include "BKE_idcode.h"
76 #include "BKE_group.h"
78 #include "BKE_lattice.h"
79 #include "BKE_library.h"
81 #include "BKE_material.h"
83 #include "BKE_mball.h"
84 #include "BKE_modifier.h"
86 #include "BKE_object.h"
87 #include "BKE_rigidbody.h"
88 #include "BKE_sound.h"
89 #include "BKE_texture.h"
90 #include "BKE_tracking.h"
91 #include "BKE_world.h"
93 #include "DEG_depsgraph.h"
94 #include "DEG_depsgraph_build.h"
96 #include "RNA_access.h"
97 #include "RNA_types.h"
100 #include "intern/builder/deg_builder.h"
101 #include "intern/nodes/deg_node.h"
102 #include "intern/nodes/deg_node_component.h"
103 #include "intern/nodes/deg_node_operation.h"
104 #include "intern/depsgraph_types.h"
105 #include "intern/depsgraph_intern.h"
112 /* **** General purpose functions **** */
114 DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph) :
120 DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
124 RootDepsNode *DepsgraphNodeBuilder::add_root_node()
126 return m_graph->add_root_node();
129 IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id)
131 const char *idtype_name = BKE_idcode_to_name(GS(id->name));
132 return m_graph->add_id_node(id, string(id->name + 2) + "[" + idtype_name + "]");
135 TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source(ID *id)
137 /* determine which node to attach timesource to */
141 IDDepsNode id_node = m_graph->find_id_node(id);
143 /* depends on what this is... */
144 switch (GS(id->name)) {
145 case ID_SCE: /* Scene - Usually sequencer strip causing time remapping... */
151 case ID_GR: /* Group */
157 // XXX: time source...
159 default: /* Unhandled */
160 printf("%s(): Unhandled ID - %s \n", __func__, id->name);
167 RootDepsNode *root_node = m_graph->root_node;
169 return root_node->add_time_source("Time Source");
176 ComponentDepsNode *DepsgraphNodeBuilder::add_component_node(
178 eDepsNode_Type comp_type,
179 const string &comp_name)
181 IDDepsNode *id_node = add_id_node(id);
182 ComponentDepsNode *comp_node = id_node->add_component(comp_type, comp_name);
183 comp_node->owner = id_node;
187 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
188 ComponentDepsNode *comp_node,
189 eDepsOperation_Type optype,
190 DepsEvalOperationCb op,
191 eDepsOperation_Code opcode,
192 const string &description)
194 OperationDepsNode *op_node = comp_node->has_operation(opcode, description);
195 if (op_node == NULL) {
196 op_node = comp_node->add_operation(optype, op, opcode, description);
197 m_graph->operations.push_back(op_node);
200 fprintf(stderr, "add_operation: Operation already exists - %s has %s at %p\n",
201 comp_node->identifier().c_str(),
202 op_node->identifier().c_str(),
204 BLI_assert(!"Should not happen!");
209 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
211 eDepsNode_Type comp_type,
212 const string &comp_name,
213 eDepsOperation_Type optype,
214 DepsEvalOperationCb op,
215 eDepsOperation_Code opcode,
216 const string &description)
218 ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
219 return add_operation_node(comp_node, optype, op, opcode, description);
222 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
224 eDepsNode_Type comp_type,
225 eDepsOperation_Type optype,
226 DepsEvalOperationCb op,
227 eDepsOperation_Code opcode,
228 const string& description)
230 return add_operation_node(id, comp_type, "", optype, op, opcode, description);
233 bool DepsgraphNodeBuilder::has_operation_node(ID *id,
234 eDepsNode_Type comp_type,
235 const string &comp_name,
236 eDepsOperation_Code opcode,
237 const string &description)
239 return find_operation_node(id, comp_type, comp_name, opcode, description) != NULL;
242 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
244 eDepsNode_Type comp_type,
245 const string &comp_name,
246 eDepsOperation_Code opcode,
247 const string &description)
249 ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
250 return comp_node->has_operation(opcode, description);
253 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
255 eDepsNode_Type comp_type,
256 eDepsOperation_Code opcode,
257 const string& description)
259 return find_operation_node(id, comp_type, "", opcode, description);
262 /* **** Build functions for entity nodes **** */
264 void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene)
266 /* LIB_TAG_DOIT is used to indicate whether node for given ID was already
267 * created or not. This flag is being set in add_id_node(), so functions
268 * shouldn't bother with setting it, they only might query this flag when
271 BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
272 /* XXX nested node trees are not included in tag-clearing above,
273 * so we need to do this manually.
275 FOREACH_NODETREE(bmain, nodetree, id) {
276 if (id != (ID *)nodetree)
277 nodetree->id.tag &= ~LIB_TAG_DOIT;
278 } FOREACH_NODETREE_END
281 add_id_node(&scene->id);
284 add_time_source(NULL);
286 /* build subgraph for set, and link this in... */
287 // XXX: depending on how this goes, that scene itself could probably store its
288 // own little partial depsgraph?
290 build_scene(bmain, scene->set);
294 for (Base *base = (Base *)scene->base.first; base; base = base->next) {
295 Object *ob = base->object;
297 /* object that this is a proxy for */
298 // XXX: the way that proxies work needs to be completely reviewed!
300 ob->proxy->proxy_from = ob;
304 build_object(scene, base, ob);
306 /* Object dupligroup. */
308 build_group(scene, base, ob->dup_group);
313 if (scene->rigidbody_world) {
314 build_rigidbody(scene);
317 /* scene's animation and drivers */
319 build_animdata(&scene->id);
324 build_world(scene->world);
328 if (scene->nodetree) {
329 build_compositor(scene);
337 build_gpencil(scene->gpd);
341 void DepsgraphNodeBuilder::build_group(Scene *scene,
345 ID *group_id = &group->id;
346 if (group_id->tag & LIB_TAG_DOIT) {
349 group_id->tag |= LIB_TAG_DOIT;
351 for (GroupObject *go = (GroupObject *)group->gobject.first;
355 build_object(scene, base, go->ob);
359 SubgraphDepsNode *DepsgraphNodeBuilder::build_subgraph(Group *group)
365 /* create new subgraph's data */
366 Depsgraph *subgraph = reinterpret_cast<Depsgraph *>(DEG_graph_new());
368 DepsgraphNodeBuilder subgraph_builder(m_bmain, subgraph);
370 /* add group objects */
371 for (GroupObject *go = (GroupObject *)group->gobject.first;
375 /*Object *ob = go->ob;*/
377 /* Each "group object" is effectively a separate instance of the underlying
378 * object data. When the group is evaluated, the transform results and/or
379 * some other attributes end up getting overridden by the group
383 /* create a node for representing subgraph */
384 SubgraphDepsNode *subgraph_node = m_graph->add_subgraph_node(&group->id);
385 subgraph_node->graph = subgraph;
387 /* make a copy of the data this node will need? */
388 // XXX: do we do this now, or later?
389 // TODO: need API function which queries graph's ID's hash, and duplicates those blocks thoroughly with all outside links removed...
391 return subgraph_node;
394 void DepsgraphNodeBuilder::build_object(Scene *scene, Base *base, Object *ob)
396 if (ob->id.tag & LIB_TAG_DOIT) {
397 IDDepsNode *id_node = m_graph->find_id_node(&ob->id);
398 id_node->layers = base->lay;
402 IDDepsNode *id_node = add_id_node(&ob->id);
403 id_node->layers = base->lay;
404 ob->customdata_mask = 0;
406 /* standard components */
407 build_object_transform(scene, ob);
411 /* type-specific data... */
413 case OB_MESH: /* Geometry */
420 /* TODO(sergey): This way using this object's
421 * properties as driver target works fine.
423 * Does this depend on other nodes?
425 add_operation_node(&ob->id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_POST, NULL,
426 DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
428 build_obdata_geom(scene, ob);
429 /* TODO(sergey): Only for until we support granular
432 if (ob->type == OB_FONT) {
433 Curve *curve = (Curve *)ob->data;
434 if (curve->textoncurve) {
435 id_node->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
441 case OB_ARMATURE: /* Pose */
442 if (ob->id.lib != NULL && ob->proxy_from != NULL) {
446 build_rig(scene, ob);
450 case OB_LAMP: /* Lamp */
454 case OB_CAMERA: /* Camera */
460 ID *obdata = (ID *)ob->data;
461 if ((obdata->tag & LIB_TAG_DOIT) == 0) {
462 build_animdata(obdata);
469 /* Build animation data,
471 * Do it now because it's possible object data will affect
472 * on object's level animation, for example in case of rebuilding
475 build_animdata(&ob->id);
479 build_gpencil(ob->gpd);
482 if (ob->proxy != NULL) {
483 add_operation_node(&ob->id, DEPSNODE_TYPE_PROXY, DEPSOP_TYPE_POST,
484 function_bind(BKE_object_eval_proxy_backlink, _1, ob),
485 DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
489 void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob)
491 /* local transforms (from transform channels - loc/rot/scale + deltas) */
492 add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
493 DEPSOP_TYPE_INIT, function_bind(BKE_object_eval_local_transform, _1, scene, ob),
494 DEG_OPCODE_TRANSFORM_LOCAL);
498 add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
499 DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_parent, _1, scene, ob),
500 DEG_OPCODE_TRANSFORM_PARENT);
503 /* object constraints */
504 if (ob->constraints.first) {
505 build_object_constraints(scene, ob);
508 /* Temporary uber-update node, which does everything.
509 * It is for the being we're porting old dependencies into the new system.
510 * We'll get rid of this node as soon as all the granular update functions
513 * TODO(sergey): Get rid of this node.
515 add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
516 DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_uber_transform, _1, scene, ob),
517 DEG_OPCODE_OBJECT_UBEREVAL);
519 /* object transform is done */
520 add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
521 DEPSOP_TYPE_POST, function_bind(BKE_object_eval_done, _1, ob),
522 DEG_OPCODE_TRANSFORM_FINAL);
526 * Constraints Graph Notes
528 * For constraints, we currently only add a operation node to the Transform
529 * or Bone components (depending on whichever type of owner we have).
530 * This represents the entire constraints stack, which is for now just
531 * executed as a single monolithic block. At least initially, this should
532 * be sufficient for ensuring that the porting/refactoring process remains
535 * However, when the time comes for developing "node-based" constraints,
536 * we'll need to split this up into pre/post nodes for "constraint stack
537 * evaluation" + operation nodes for each constraint (i.e. the contents
538 * of the loop body used in the current "solve_constraints()" operation).
540 * -- Aligorith, August 2013
542 void DepsgraphNodeBuilder::build_object_constraints(Scene *scene, Object *ob)
544 /* create node for constraint stack */
545 add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
546 DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_constraints, _1, scene, ob),
547 DEG_OPCODE_TRANSFORM_CONSTRAINTS);
550 void DepsgraphNodeBuilder::build_pose_constraints(Object *ob, bPoseChannel *pchan)
552 /* create node for constraint stack */
553 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
554 DEPSOP_TYPE_EXEC, function_bind(BKE_pose_constraints_evaluate, _1, ob, pchan),
555 DEG_OPCODE_BONE_CONSTRAINTS);
559 * Build graph nodes for AnimData block
560 * \param id: ID-Block which hosts the AnimData
562 void DepsgraphNodeBuilder::build_animdata(ID *id)
564 AnimData *adt = BKE_animdata_from_id(id);
570 if (adt->action || adt->nla_tracks.first || adt->drivers.first) {
571 // XXX: Hook up specific update callbacks for special properties which may need it...
573 /* actions and NLA - as a single unit for now, as it gets complicated to schedule otherwise */
574 if ((adt->action) || (adt->nla_tracks.first)) {
575 /* create the node */
576 add_operation_node(id, DEPSNODE_TYPE_ANIMATION,
577 DEPSOP_TYPE_EXEC, function_bind(BKE_animsys_eval_animdata, _1, id),
578 DEG_OPCODE_ANIMATION, id->name);
580 // TODO: for each channel affected, we might also want to add some support for running RNA update callbacks on them
581 // (which will be needed for proper handling of drivers later)
585 for (FCurve *fcu = (FCurve *)adt->drivers.first; fcu; fcu = fcu->next) {
587 build_driver(id, fcu);
593 * Build graph node(s) for Driver
594 * \param id: ID-Block that driver is attached to
595 * \param fcu: Driver-FCurve
597 OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu)
599 ChannelDriver *driver = fcu->driver;
601 /* Create data node for this driver */
602 /* TODO(sergey): Avoid creating same operation multiple times,
603 * in the future we need to avoid lookup of the operation as well
604 * and use some tagging magic instead.
606 OperationDepsNode *driver_op = find_operation_node(id,
607 DEPSNODE_TYPE_PARAMETERS,
609 deg_fcurve_id_name(fcu));
611 if (driver_op == NULL) {
612 driver_op = add_operation_node(id, DEPSNODE_TYPE_PARAMETERS,
613 DEPSOP_TYPE_EXEC, function_bind(BKE_animsys_eval_driver, _1, id, fcu),
614 DEG_OPCODE_DRIVER, deg_fcurve_id_name(fcu));
617 /* tag "scripted expression" drivers as needing Python (due to GIL issues, etc.) */
618 if (driver->type == DRIVER_TYPE_PYTHON) {
619 driver_op->flag |= DEPSOP_FLAG_USES_PYTHON;
622 /* return driver node created */
626 /* Recursively build graph for world */
627 void DepsgraphNodeBuilder::build_world(World *world)
629 ID *world_id = &world->id;
630 if (world_id->tag & LIB_TAG_DOIT) {
635 IDDepsNode *world_node = add_id_node(world_id); /* world shading/params? */
637 build_animdata(world_id);
639 /* TODO: other settings? */
642 build_texture_stack(world_node, world->mtex);
644 /* world's nodetree */
645 if (world->nodetree) {
646 build_nodetree(world_node, world->nodetree);
650 /* Rigidbody Simulation - Scene Level */
651 void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
653 RigidBodyWorld *rbw = scene->rigidbody_world;
656 * Rigidbody Simulation Nodes
657 * ==========================
659 * There are 3 nodes related to Rigidbody Simulation:
660 * 1) "Initialize/Rebuild World" - this is called sparingly, only when the simulation
661 * needs to be rebuilt (mainly after file reload, or moving back to start frame)
662 * 2) "Do Simulation" - perform a simulation step - interleaved between the evaluation
663 * steps for clusters of objects (i.e. between those affected and/or not affected by
664 * the sim for instance)
666 * 3) "Pull Results" - grab the specific transforms applied for a specific object -
667 * performed as part of object's transform-stack building
670 /* create nodes ------------------------------------------------------------------------ */
671 /* XXX: is this the right component, or do we want to use another one instead? */
673 /* init/rebuild operation */
674 /*OperationDepsNode *init_node =*/ add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM,
675 DEPSOP_TYPE_REBUILD, function_bind(BKE_rigidbody_rebuild_sim, _1, scene),
676 DEG_OPCODE_RIGIDBODY_REBUILD);
678 /* do-sim operation */
679 // XXX: what happens if we need to split into several groups?
680 OperationDepsNode *sim_node = add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM,
681 DEPSOP_TYPE_SIM, function_bind(BKE_rigidbody_eval_simulation, _1, scene),
682 DEG_OPCODE_RIGIDBODY_SIM);
684 /* XXX: For now, the sim node is the only one that really matters here. If any other
685 * sims get added later, we may have to remove these hacks...
687 sim_node->owner->entry_operation = sim_node;
688 sim_node->owner->exit_operation = sim_node;
691 /* objects - simulation participants */
693 for (GroupObject *go = (GroupObject *)rbw->group->gobject.first; go; go = go->next) {
696 if (!ob || (ob->type != OB_MESH))
699 /* 2) create operation for flushing results */
700 /* object's transform component - where the rigidbody operation lives */
701 add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
702 DEPSOP_TYPE_EXEC, function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, ob),
703 DEG_OPCODE_TRANSFORM_RIGIDBODY);
708 /* IK Solver Eval Steps */
709 void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
711 bKinematicConstraint *data = (bKinematicConstraint *)con->data;
713 /* Find the chain's root. */
714 bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data);
716 if (has_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
717 DEG_OPCODE_POSE_IK_SOLVER))
722 /* Operation node for evaluating/running IK Solver. */
723 add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
724 DEPSOP_TYPE_SIM, function_bind(BKE_pose_iktree_evaluate, _1, scene, ob, rootchan),
725 DEG_OPCODE_POSE_IK_SOLVER);
728 /* Spline IK Eval Steps */
729 void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
731 bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
733 /* Find the chain's root. */
734 bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
736 /* Operation node for evaluating/running Spline IK Solver.
737 * Store the "root bone" of this chain in the solver, so it knows where to start.
739 add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
740 DEPSOP_TYPE_SIM, function_bind(BKE_pose_splineik_evaluate, _1, scene, ob, rootchan),
741 DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
744 /* Pose/Armature Bones Graph */
745 void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob)
747 bArmature *arm = (bArmature *)ob->data;
749 /* animation and/or drivers linking posebones to base-armature used to define them
750 * NOTE: AnimData here is really used to control animated deform properties,
751 * which ideally should be able to be unique across different instances.
752 * Eventually, we need some type of proxy/isolation mechanism in-between here
753 * to ensure that we can use same rig multiple times in same scene...
755 build_animdata(&arm->id);
757 /* Rebuild pose if not up to date. */
758 if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) {
759 BKE_pose_rebuild(ob, arm);
760 /* XXX: Without this animation gets lost in certain circumstances
761 * after loading file. Need to investigate further since it does
762 * not happen with simple scenes..
765 ob->adt->recalc |= ADT_RECALC_ANIM;
769 /* speed optimization for animation lookups */
771 BKE_pose_channels_hash_make(ob->pose);
772 if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
773 BKE_pose_update_constraint_flags(ob->pose);
777 /* Make sure pose is up-to-date with armature updates. */
778 add_operation_node(&arm->id,
779 DEPSNODE_TYPE_PARAMETERS,
782 DEG_OPCODE_PLACEHOLDER,
790 * - Mainly used for referencing Bone components.
791 * - This is where the evaluation operations for init/exec/cleanup
792 * (ik) solvers live, and are later hooked up (so that they can be
793 * interleaved during runtime) with bone-operations they depend on/affect.
794 * - init_pose_eval() and cleanup_pose_eval() are absolute first and last
795 * steps of pose eval process. ALL bone operations must be performed
796 * between these two...
799 * - Used for representing each bone within the rig
800 * - Acts to encapsulate the evaluation operations (base matrix + parenting,
801 * and constraint stack) so that they can be easily found.
802 * - Everything else which depends on bone-results hook up to the component only
803 * so that we can redirect those to point at either the the post-IK/
804 * post-constraint/post-matrix steps, as needed.
807 /* pose eval context */
808 add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE,
809 DEPSOP_TYPE_INIT, function_bind(BKE_pose_eval_init, _1, scene, ob, ob->pose), DEG_OPCODE_POSE_INIT);
811 add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE,
812 DEPSOP_TYPE_POST, function_bind(BKE_pose_eval_flush, _1, scene, ob, ob->pose), DEG_OPCODE_POSE_DONE);
815 for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) {
816 /* node for bone eval */
817 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
818 DEPSOP_TYPE_INIT, NULL, // XXX: BKE_pose_eval_bone_local
819 DEG_OPCODE_BONE_LOCAL);
821 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
822 DEPSOP_TYPE_EXEC, function_bind(BKE_pose_eval_bone, _1, scene, ob, pchan), // XXX: BKE_pose_eval_bone_pose
823 DEG_OPCODE_BONE_POSE_PARENT);
825 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
826 DEPSOP_TYPE_OUT, NULL, /* NOTE: dedicated noop for easier relationship construction */
827 DEG_OPCODE_BONE_READY);
829 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
830 DEPSOP_TYPE_POST, function_bind(BKE_pose_bone_done, _1, pchan),
831 DEG_OPCODE_BONE_DONE);
834 if (pchan->constraints.first != NULL) {
835 build_pose_constraints(ob, pchan);
841 * - These require separate processing steps are pose-level
842 * to be executed between chains of bones (i.e. once the
843 * base transforms of a bunch of bones is done)
846 * - Care is needed to ensure that multi-headed trees work out the same as in ik-tree building
847 * - Animated chain-lengths are a problem...
849 for (bConstraint *con = (bConstraint *)pchan->constraints.first; con; con = con->next) {
851 case CONSTRAINT_TYPE_KINEMATIC:
852 build_ik_pose(scene, ob, pchan, con);
855 case CONSTRAINT_TYPE_SPLINEIK:
856 build_splineik_pose(scene, ob, pchan, con);
866 void DepsgraphNodeBuilder::build_proxy_rig(Object *ob)
868 ID *obdata = (ID *)ob->data;
869 build_animdata(obdata);
871 BLI_assert(ob->pose != NULL);
873 /* speed optimization for animation lookups */
874 BKE_pose_channels_hash_make(ob->pose);
875 if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
876 BKE_pose_update_constraint_flags(ob->pose);
879 add_operation_node(&ob->id,
880 DEPSNODE_TYPE_EVAL_POSE,
882 function_bind(BKE_pose_eval_proxy_copy, _1, ob),
883 DEG_OPCODE_POSE_INIT);
885 for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first;
889 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
890 DEPSOP_TYPE_INIT, NULL,
891 DEG_OPCODE_BONE_LOCAL);
893 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
894 DEPSOP_TYPE_EXEC, NULL,
895 DEG_OPCODE_BONE_READY);
897 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
898 DEPSOP_TYPE_POST, NULL,
899 DEG_OPCODE_BONE_DONE);
902 add_operation_node(&ob->id,
903 DEPSNODE_TYPE_EVAL_POSE,
906 DEG_OPCODE_POSE_DONE);
910 void DepsgraphNodeBuilder::build_shapekeys(Key *key)
912 build_animdata(&key->id);
914 add_operation_node(&key->id, DEPSNODE_TYPE_GEOMETRY, DEPSOP_TYPE_EXEC, NULL,
915 DEG_OPCODE_PLACEHOLDER, "Shapekey Eval");
918 /* ObData Geometry Evaluation */
919 // XXX: what happens if the datablock is shared!
920 void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
922 ID *obdata = (ID *)ob->data;
924 /* Temporary uber-update node, which does everything.
925 * It is for the being we're porting old dependencies into the new system.
926 * We'll get rid of this node as soon as all the granular update functions
929 * TODO(sergey): Get rid of this node.
931 add_operation_node(&ob->id, DEPSNODE_TYPE_GEOMETRY,
932 DEPSOP_TYPE_POST, function_bind(BKE_object_eval_uber_data, _1, scene, ob),
933 DEG_OPCODE_GEOMETRY_UBEREVAL);
935 add_operation_node(&ob->id, DEPSNODE_TYPE_GEOMETRY,
936 DEPSOP_TYPE_INIT, NULL,
937 DEG_OPCODE_PLACEHOLDER, "Eval Init");
939 // TODO: "Done" operation
942 Key *key = BKE_key_from_object(ob);
944 build_shapekeys(key);
947 if (ob->modifiers.first) {
950 for (md = (ModifierData *)ob->modifiers.first; md; md = md->next) {
951 add_operation_node(&ob->id, DEPSNODE_TYPE_GEOMETRY,
952 DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_modifier, _1, scene, ob, md),
953 DEG_OPCODE_GEOMETRY_MODIFIER, md->name);
961 for (a = 1; a <= ob->totcol; a++) {
962 Material *ma = give_current_material(ob, a);
966 ComponentDepsNode *geom_node = add_component_node(&ob->id, DEPSNODE_TYPE_GEOMETRY);
967 build_material(geom_node, ma);
972 /* geometry collision */
973 if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
974 // add geometry collider relations
977 if (obdata->tag & LIB_TAG_DOIT) {
981 build_animdata(obdata);
983 /* nodes for result of obdata's evaluation, and geometry evaluation on object */
987 //Mesh *me = (Mesh *)ob->data;
989 /* evaluation operations */
990 add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
991 DEPSOP_TYPE_INIT, function_bind(BKE_mesh_eval_geometry, _1, (Mesh *)obdata),
992 DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
998 Object *mom = BKE_mball_basis_find(scene, ob);
1000 /* motherball - mom depends on children! */
1002 /* metaball evaluation operations */
1003 /* NOTE: only the motherball gets evaluated! */
1004 add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
1005 DEPSOP_TYPE_INIT, function_bind(BKE_mball_eval_geometry, _1, (MetaBall *)obdata),
1006 DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
1014 /* curve evaluation operations */
1015 /* - calculate curve geometry (including path) */
1016 add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
1017 DEPSOP_TYPE_INIT, function_bind(BKE_curve_eval_geometry, _1, (Curve *)obdata),
1018 DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
1020 /* - calculate curve path - this is used by constraints, etc. */
1021 add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
1022 DEPSOP_TYPE_EXEC, function_bind(BKE_curve_eval_path, _1, (Curve *)obdata),
1023 DEG_OPCODE_GEOMETRY_PATH, "Path");
1027 case OB_SURF: /* Nurbs Surface */
1029 /* nurbs evaluation operations */
1030 add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
1031 DEPSOP_TYPE_INIT, function_bind(BKE_curve_eval_geometry, _1, (Curve *)obdata),
1032 DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
1036 case OB_LATTICE: /* Lattice */
1038 /* lattice evaluation operations */
1039 add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
1040 DEPSOP_TYPE_INIT, function_bind(BKE_lattice_eval_geometry, _1, (Lattice *)obdata),
1041 DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
1046 add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
1047 DEPSOP_TYPE_POST, NULL,
1048 DEG_OPCODE_PLACEHOLDER, "Eval Done");
1050 /* Parameters for driver sources. */
1051 add_operation_node(obdata, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL,
1052 DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1056 void DepsgraphNodeBuilder::build_camera(Object *ob)
1058 /* TODO: Link scene-camera links in somehow... */
1059 Camera *cam = (Camera *)ob->data;
1060 ID *camera_id = &cam->id;
1061 if (camera_id->tag & LIB_TAG_DOIT) {
1065 build_animdata(&cam->id);
1067 add_operation_node(camera_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL,
1068 DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1070 if (cam->dof_ob != NULL) {
1071 /* TODO(sergey): For now parametrs are on object level. */
1072 add_operation_node(&ob->id, DEPSNODE_TYPE_PARAMETERS,
1073 DEPSOP_TYPE_EXEC, NULL,
1074 DEG_OPCODE_PLACEHOLDER,
1080 void DepsgraphNodeBuilder::build_lamp(Object *ob)
1082 Lamp *la = (Lamp *)ob->data;
1083 ID *lamp_id = &la->id;
1084 if (lamp_id->tag & LIB_TAG_DOIT) {
1088 build_animdata(&la->id);
1090 /* node for obdata */
1091 ComponentDepsNode *param_node = add_component_node(lamp_id, DEPSNODE_TYPE_PARAMETERS);
1093 /* TODO(sergey): Is it really how we're supposed to work with drivers? */
1094 add_operation_node(lamp_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL,
1095 DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1097 /* lamp's nodetree */
1099 build_nodetree(param_node, la->nodetree);
1103 build_texture_stack(param_node, la->mtex);
1106 void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree)
1111 /* nodetree itself */
1112 ID *ntree_id = &ntree->id;
1114 build_animdata(ntree_id);
1116 /* Parameters for drivers. */
1117 add_operation_node(ntree_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_POST, NULL,
1118 DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1120 /* nodetree's nodes... */
1121 for (bNode *bnode = (bNode *)ntree->nodes.first; bnode; bnode = bnode->next) {
1123 if (GS(bnode->id->name) == ID_MA) {
1124 build_material(owner_node, (Material *)bnode->id);
1126 else if (bnode->type == ID_TE) {
1127 build_texture(owner_node, (Tex *)bnode->id);
1129 else if (bnode->type == NODE_GROUP) {
1130 bNodeTree *group_ntree = (bNodeTree *)bnode->id;
1131 if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) {
1132 build_nodetree(owner_node, group_ntree);
1138 // TODO: link from nodetree to owner_component?
1141 /* Recursively build graph for material */
1142 void DepsgraphNodeBuilder::build_material(DepsNode *owner_node, Material *ma)
1144 ID *ma_id = &ma->id;
1145 if (ma_id->tag & LIB_TAG_DOIT) {
1149 /* material itself */
1152 add_operation_node(ma_id, DEPSNODE_TYPE_SHADING,
1153 DEPSOP_TYPE_EXEC, NULL,
1154 DEG_OPCODE_PLACEHOLDER, "Material Update");
1156 /* material animation */
1157 build_animdata(ma_id);
1160 build_texture_stack(owner_node, ma->mtex);
1162 /* material's nodetree */
1163 build_nodetree(owner_node, ma->nodetree);
1166 /* Texture-stack attached to some shading datablock */
1167 void DepsgraphNodeBuilder::build_texture_stack(DepsNode *owner_node, MTex **texture_stack)
1171 /* for now assume that all texture-stacks have same number of max items */
1172 for (i = 0; i < MAX_MTEX; i++) {
1173 MTex *mtex = texture_stack[i];
1174 if (mtex && mtex->tex)
1175 build_texture(owner_node, mtex->tex);
1179 /* Recursively build graph for texture */
1180 void DepsgraphNodeBuilder::build_texture(DepsNode *owner_node, Tex *tex)
1182 ID *tex_id = &tex->id;
1183 if (tex_id->tag & LIB_TAG_DOIT) {
1186 tex_id->tag |= LIB_TAG_DOIT;
1187 /* texture itself */
1188 build_animdata(tex_id);
1189 /* texture's nodetree */
1190 build_nodetree(owner_node, tex->nodetree);
1193 void DepsgraphNodeBuilder::build_compositor(Scene *scene)
1195 /* For now, just a plain wrapper? */
1196 // TODO: create compositing component?
1197 // XXX: component type undefined!
1198 //graph->get_node(&scene->id, NULL, DEPSNODE_TYPE_COMPOSITING, NULL);
1200 /* for now, nodetrees are just parameters; compositing occurs in internals of renderer... */
1201 ComponentDepsNode *owner_node = add_component_node(&scene->id, DEPSNODE_TYPE_PARAMETERS);
1202 build_nodetree(owner_node, scene->nodetree);
1205 void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd)
1207 ID *gpd_id = &gpd->id;
1209 /* gpencil itself */
1210 // XXX: what about multiple users of same datablock? This should only get added once
1211 add_id_node(gpd_id);
1213 /* The main reason Grease Pencil is included here is because the animation (and drivers)
1214 * need to be hosted somewhere...
1216 build_animdata(gpd_id);