Merge branch 'master' into blender2.8
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes.cc
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
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.
8  *
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.
13  *
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.
17  *
18  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Joshua Leung
22  * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_nodes.cc
28  *  \ingroup depsgraph
29  *
30  * Methods for constructing depsgraph's nodes
31  */
32
33 #include "intern/builder/deg_builder_nodes.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_string.h"
42 #include "BLI_utildefines.h"
43
44 extern "C" {
45 #include "DNA_action_types.h"
46 #include "DNA_anim_types.h"
47 #include "DNA_armature_types.h"
48 #include "DNA_cachefile_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_mask_types.h"
59 #include "DNA_mesh_types.h"
60 #include "DNA_meta_types.h"
61 #include "DNA_movieclip_types.h"
62 #include "DNA_node_types.h"
63 #include "DNA_particle_types.h"
64 #include "DNA_object_types.h"
65 #include "DNA_lightprobe_types.h"
66 #include "DNA_rigidbody_types.h"
67 #include "DNA_scene_types.h"
68 #include "DNA_texture_types.h"
69 #include "DNA_world_types.h"
70
71 #include "BKE_action.h"
72 #include "BKE_armature.h"
73 #include "BKE_animsys.h"
74 #include "BKE_constraint.h"
75 #include "BKE_curve.h"
76 #include "BKE_effect.h"
77 #include "BKE_fcurve.h"
78 #include "BKE_idcode.h"
79 #include "BKE_group.h"
80 #include "BKE_key.h"
81 #include "BKE_lattice.h"
82 #include "BKE_library.h"
83 #include "BKE_main.h"
84 #include "BKE_mask.h"
85 #include "BKE_material.h"
86 #include "BKE_mesh.h"
87 #include "BKE_mball.h"
88 #include "BKE_modifier.h"
89 #include "BKE_movieclip.h"
90 #include "BKE_node.h"
91 #include "BKE_object.h"
92 #include "BKE_particle.h"
93 #include "BKE_rigidbody.h"
94 #include "BKE_sound.h"
95 #include "BKE_tracking.h"
96 #include "BKE_world.h"
97
98 #include "RNA_access.h"
99 #include "RNA_types.h"
100 } /* extern "C" */
101
102 #include "DEG_depsgraph.h"
103 #include "DEG_depsgraph_build.h"
104
105 #include "intern/builder/deg_builder.h"
106 #include "intern/eval/deg_eval_copy_on_write.h"
107 #include "intern/nodes/deg_node.h"
108 #include "intern/nodes/deg_node_component.h"
109 #include "intern/nodes/deg_node_id.h"
110 #include "intern/nodes/deg_node_operation.h"
111 #include "intern/depsgraph_types.h"
112 #include "intern/depsgraph_intern.h"
113
114 #include "util/deg_util_foreach.h"
115
116 namespace DEG {
117
118 namespace {
119
120 struct BuilderWalkUserData {
121         DepsgraphNodeBuilder *builder;
122 };
123
124 static void modifier_walk(void *user_data,
125                           struct Object * /*object*/,
126                           struct Object **obpoin,
127                           int /*cb_flag*/)
128 {
129         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
130         if (*obpoin) {
131                 data->builder->build_object(NULL,
132                                             *obpoin,
133                                             DEG_ID_LINKED_INDIRECTLY);
134         }
135 }
136
137 void constraint_walk(bConstraint * /*con*/,
138                      ID **idpoin,
139                      bool /*is_reference*/,
140                      void *user_data)
141 {
142         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
143         if (*idpoin) {
144                 ID *id = *idpoin;
145                 if (GS(id->name) == ID_OB) {
146                         data->builder->build_object(NULL,
147                                                     (Object *)id,
148                                                     DEG_ID_LINKED_INDIRECTLY);
149                 }
150         }
151 }
152
153 void free_copy_on_write_datablock(void *id_v)
154 {
155         ID *id = (ID *)id_v;
156         deg_free_copy_on_write_datablock(id);
157 }
158
159 }  /* namespace */
160
161 /* ************ */
162 /* Node Builder */
163
164 /* **** General purpose functions **** */
165
166 DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph)
167     : bmain_(bmain),
168       graph_(graph),
169       scene_(NULL),
170       cow_id_hash_(NULL)
171 {
172 }
173
174 DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
175 {
176         if (cow_id_hash_ != NULL) {
177                 BLI_ghash_free(cow_id_hash_, NULL, free_copy_on_write_datablock);
178         }
179 }
180
181 IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id, bool do_tag)
182 {
183         if (!DEG_depsgraph_use_copy_on_write()) {
184                 return graph_->add_id_node(id, do_tag);
185         }
186         IDDepsNode *id_node = NULL;
187         ID *id_cow = (ID *)BLI_ghash_lookup(cow_id_hash_, id);
188         if (id_cow != NULL) {
189                 /* TODO(sergey): Is it possible to lookup and pop element from GHash
190                  * at the same time?
191                  */
192                 BLI_ghash_remove(cow_id_hash_, id, NULL, NULL);
193         }
194         id_node = graph_->add_id_node(id, do_tag, id_cow);
195         /* Currently all ID nodes are supposed to have copy-on-write logic.
196          *
197          * NOTE: Zero number of components indicates that ID node was just created.
198          */
199         if (BLI_ghash_size(id_node->components) == 0) {
200                 ComponentDepsNode *comp_cow =
201                         id_node->add_component(DEG_NODE_TYPE_COPY_ON_WRITE);
202                 OperationDepsNode *op_cow = comp_cow->add_operation(
203                         function_bind(deg_evaluate_copy_on_write, _1, graph_, id_node),
204                         DEG_OPCODE_COPY_ON_WRITE,
205                         "", -1);
206                 graph_->operations.push_back(op_cow);
207         }
208         return id_node;
209 }
210
211 IDDepsNode *DepsgraphNodeBuilder::find_id_node(ID *id)
212 {
213         return graph_->find_id_node(id);
214 }
215
216 TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source()
217 {
218         return graph_->add_time_source();
219 }
220
221 ComponentDepsNode *DepsgraphNodeBuilder::add_component_node(
222         ID *id,
223         eDepsNode_Type comp_type,
224         const char *comp_name)
225 {
226         IDDepsNode *id_node = add_id_node(id);
227         ComponentDepsNode *comp_node = id_node->add_component(comp_type, comp_name);
228         comp_node->owner = id_node;
229         return comp_node;
230 }
231
232 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
233         ComponentDepsNode *comp_node,
234         const DepsEvalOperationCb& op,
235         eDepsOperation_Code opcode,
236         const char *name,
237         int name_tag)
238 {
239         OperationDepsNode *op_node = comp_node->find_operation(opcode,
240                                                                name,
241                                                                name_tag);
242         if (op_node == NULL) {
243                 op_node = comp_node->add_operation(op, opcode, name, name_tag);
244                 graph_->operations.push_back(op_node);
245         }
246         else {
247                 fprintf(stderr,
248                         "add_operation: Operation already exists - %s has %s at %p\n",
249                         comp_node->identifier().c_str(),
250                         op_node->identifier().c_str(),
251                         op_node);
252                 BLI_assert(!"Should not happen!");
253         }
254         return op_node;
255 }
256
257 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
258         ID *id,
259         eDepsNode_Type comp_type,
260         const char *comp_name,
261         const DepsEvalOperationCb& op,
262         eDepsOperation_Code opcode,
263         const char *name,
264         int name_tag)
265 {
266         ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
267         return add_operation_node(comp_node, op, opcode, name, name_tag);
268 }
269
270 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
271         ID *id,
272         eDepsNode_Type comp_type,
273         const DepsEvalOperationCb& op,
274         eDepsOperation_Code opcode,
275         const char *name,
276         int name_tag)
277 {
278         return add_operation_node(id,
279                                   comp_type,
280                                   "",
281                                   op,
282                                   opcode,
283                                   name,
284                                   name_tag);
285 }
286
287 bool DepsgraphNodeBuilder::has_operation_node(ID *id,
288                                               eDepsNode_Type comp_type,
289                                               const char *comp_name,
290                                               eDepsOperation_Code opcode,
291                                               const char *name,
292                                               int name_tag)
293 {
294         return find_operation_node(id,
295                                    comp_type,
296                                    comp_name,
297                                    opcode,
298                                    name,
299                                    name_tag) != NULL;
300 }
301
302 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
303         ID *id,
304         eDepsNode_Type comp_type,
305         const char *comp_name,
306         eDepsOperation_Code opcode,
307         const char *name,
308         int name_tag)
309 {
310         ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
311         return comp_node->find_operation(opcode, name, name_tag);
312 }
313
314 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
315         ID *id,
316         eDepsNode_Type comp_type,
317         eDepsOperation_Code opcode,
318         const char *name,
319         int name_tag)
320 {
321         return find_operation_node(id, comp_type, "", opcode, name, name_tag);
322 }
323
324 ID *DepsgraphNodeBuilder::get_cow_id(const ID *id_orig) const
325 {
326         return graph_->get_cow_id(id_orig);
327 }
328
329 ID *DepsgraphNodeBuilder::ensure_cow_id(ID *id_orig)
330 {
331         if (id_orig->tag & LIB_TAG_COPY_ON_WRITE) {
332                 /* ID is already remapped to copy-on-write. */
333                 return id_orig;
334         }
335         IDDepsNode *id_node = add_id_node(id_orig, false);
336         return id_node->id_cow;
337 }
338
339 ID *DepsgraphNodeBuilder::expand_cow_id(IDDepsNode *id_node)
340 {
341         return deg_expand_copy_on_write_datablock(graph_, id_node, this, true);
342 }
343
344 ID *DepsgraphNodeBuilder::expand_cow_id(ID *id_orig)
345 {
346         IDDepsNode *id_node = add_id_node(id_orig);
347         return expand_cow_id(id_node);
348 }
349
350 /* **** Build functions for entity nodes **** */
351
352 void DepsgraphNodeBuilder::begin_build() {
353         /* LIB_TAG_DOIT is used to indicate whether node for given ID was already
354          * created or not. This flag is being set in add_id_node(), so functions
355          * shouldn't bother with setting it, they only might query this flag when
356          * needed.
357          */
358         BKE_main_id_tag_all(bmain_, LIB_TAG_DOIT, false);
359         /* XXX nested node trees are not included in tag-clearing above,
360          * so we need to do this manually.
361          */
362         FOREACH_NODETREE(bmain_, nodetree, id)
363         {
364                 if (id != (ID *)nodetree) {
365                         nodetree->id.tag &= ~LIB_TAG_DOIT;
366                 }
367         }
368         FOREACH_NODETREE_END;
369
370         if (DEG_depsgraph_use_copy_on_write()) {
371                 /* Store existing copy-on-write versions of datablock, so we can re-use
372                  * them for new ID nodes.
373                  */
374                 cow_id_hash_ = BLI_ghash_ptr_new("Depsgraph id hash");
375                 foreach (IDDepsNode *id_node, graph_->id_nodes) {
376                         if (deg_copy_on_write_is_expanded(id_node->id_cow)) {
377                                 BLI_ghash_insert(cow_id_hash_,
378                                                  id_node->id_orig,
379                                                  id_node->id_cow);
380                                 id_node->id_cow = NULL;
381                         }
382                 }
383         }
384
385         GSET_FOREACH_BEGIN(OperationDepsNode *, op_node, graph_->entry_tags)
386         {
387                 ComponentDepsNode *comp_node = op_node->owner;
388                 IDDepsNode *id_node = comp_node->owner;
389
390                 SavedEntryTag entry_tag;
391                 entry_tag.id = id_node->id_orig;
392                 entry_tag.component_type = comp_node->type;
393                 entry_tag.opcode = op_node->opcode;
394                 saved_entry_tags_.push_back(entry_tag);
395         };
396         GSET_FOREACH_END();
397
398         /* Make sure graph has no nodes left from previous state. */
399         graph_->clear_all_nodes();
400         graph_->operations.clear();
401         BLI_gset_clear(graph_->entry_tags, NULL);
402 }
403
404 void DepsgraphNodeBuilder::end_build()
405 {
406         foreach (const SavedEntryTag& entry_tag, saved_entry_tags_) {
407                 IDDepsNode *id_node = find_id_node(entry_tag.id);
408                 if (id_node == NULL) {
409                         continue;
410                 }
411                 ComponentDepsNode *comp_node =
412                         id_node->find_component(entry_tag.component_type);
413                 if (comp_node == NULL) {
414                         continue;
415                 }
416                 OperationDepsNode *op_node = comp_node->find_operation(entry_tag.opcode);
417                 if (op_node == NULL) {
418                         continue;
419                 }
420                 op_node->tag_update(graph_);
421         }
422 }
423
424 void DepsgraphNodeBuilder::build_group(Group *group)
425 {
426         ID *group_id = &group->id;
427         if (group_id->tag & LIB_TAG_DOIT) {
428                 return;
429         }
430         group_id->tag |= LIB_TAG_DOIT;
431         /* Build group objects. */
432         BLI_LISTBASE_FOREACH (Base *, base, &group->view_layer->object_bases) {
433                 build_object(NULL, base->object, DEG_ID_LINKED_INDIRECTLY);
434         }
435         /* Operation to evaluate the whole view layer.
436          *
437          * NOTE: We re-use DONE opcode even though the function does everything.
438          * This way we wouldn't need to worry about possible relations from DONE,
439          * regardless whether it's a group or scene or something else.
440          */
441         add_id_node(group_id);
442         Group *group_cow = get_cow_datablock(group);
443         add_operation_node(group_id,
444                            DEG_NODE_TYPE_LAYER_COLLECTIONS,
445                            function_bind(BKE_group_eval_view_layers,
446                                          _1,
447                                          group_cow),
448                            DEG_OPCODE_VIEW_LAYER_DONE);
449 }
450
451 void DepsgraphNodeBuilder::build_object(Base *base,
452                                         Object *object,
453                                         eDepsNode_LinkedState_Type linked_state)
454 {
455         /* Skip rest of components if the ID node was already there. */
456         if (object->id.tag & LIB_TAG_DOIT) {
457                 IDDepsNode *id_node = find_id_node(&object->id);
458                 /* We need to build some extra stuff if object becomes linked
459                  * directly.
460                  */
461                 if (id_node->linked_state == DEG_ID_LINKED_INDIRECTLY) {
462                         build_object_flags(base, object, linked_state);
463                 }
464                 id_node->linked_state = max(id_node->linked_state, linked_state);
465                 return;
466         }
467         object->id.tag |= LIB_TAG_DOIT;
468         /* Create ID node for object and begin init. */
469         IDDepsNode *id_node = add_id_node(&object->id);
470         id_node->linked_state = linked_state;
471         object->customdata_mask = 0;
472         /* Various flags, flushing from bases/collections. */
473         build_object_flags(base, object, linked_state);
474         /* Transform. */
475         build_object_transform(object);
476         /* Parent. */
477         if (object->parent != NULL) {
478                 build_object(NULL, object->parent, DEG_ID_LINKED_INDIRECTLY);
479         }
480         /* Modifiers. */
481         if (object->modifiers.first != NULL) {
482                 BuilderWalkUserData data;
483                 data.builder = this;
484                 modifiers_foreachObjectLink(object, modifier_walk, &data);
485         }
486         /* Constraints. */
487         if (object->constraints.first != NULL) {
488                 BuilderWalkUserData data;
489                 data.builder = this;
490                 BKE_constraints_id_loop(&object->constraints, constraint_walk, &data);
491         }
492         /* Object data. */
493         build_object_data(object);
494         /* Build animation data,
495          *
496          * Do it now because it's possible object data will affect
497          * on object's level animation, for example in case of rebuilding
498          * pose for proxy.
499          */
500         build_animdata(&object->id);
501         /* Particle systems. */
502         if (object->particlesystem.first != NULL) {
503                 build_particles(object);
504         }
505         /* Grease pencil. */
506         if (object->gpd != NULL) {
507                 build_gpencil(object->gpd);
508         }
509         /* Object that this is a proxy for. */
510         if (object->proxy) {
511                 object->proxy->proxy_from = object;
512                 build_object(NULL, object->proxy, DEG_ID_LINKED_INDIRECTLY);
513         }
514         /* Object dupligroup. */
515         if (object->dup_group != NULL) {
516                 build_group(object->dup_group);
517         }
518 }
519
520 void DepsgraphNodeBuilder::build_object_flags(
521         Base *base,
522         Object *object,
523         eDepsNode_LinkedState_Type linked_state)
524 {
525         if (base == NULL) {
526                 return;
527         }
528         /* TODO(sergey): Is this really best component to be used? */
529         Object *object_cow = get_cow_datablock(object);
530         const bool is_from_set = (linked_state == DEG_ID_LINKED_VIA_SET);
531         add_operation_node(&object->id,
532                            DEG_NODE_TYPE_LAYER_COLLECTIONS,
533                            function_bind(BKE_object_eval_flush_base_flags,
534                                          _1, object_cow, base, is_from_set),
535                            DEG_OPCODE_OBJECT_BASE_FLAGS);
536 }
537
538 void DepsgraphNodeBuilder::build_object_data(Object *object)
539 {
540         if (object->data == NULL) {
541                 return;
542         }
543         IDDepsNode *id_node = graph_->find_id_node(&object->id);
544         /* type-specific data. */
545         switch (object->type) {
546                 case OB_MESH:
547                 case OB_CURVE:
548                 case OB_FONT:
549                 case OB_SURF:
550                 case OB_MBALL:
551                 case OB_LATTICE:
552                         build_obdata_geom(object);
553                         /* TODO(sergey): Only for until we support granular
554                          * update of curves.
555                          */
556                         if (object->type == OB_FONT) {
557                                 Curve *curve = (Curve *)object->data;
558                                 if (curve->textoncurve) {
559                                         id_node->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
560                                 }
561                         }
562                         break;
563                 case OB_ARMATURE:
564                         if (ID_IS_LINKED(object) && object->proxy_from != NULL) {
565                                 build_proxy_rig(object);
566                         }
567                         else {
568                                 build_rig(object);
569                         }
570                         break;
571                 case OB_LAMP:
572                         build_lamp(object);
573                         break;
574                 case OB_CAMERA:
575                         build_camera(object);
576                         break;
577                 case OB_LIGHTPROBE:
578                         build_lightprobe(object);
579                         break;
580                 default:
581                 {
582                         ID *obdata = (ID *)object->data;
583                         if ((obdata->tag & LIB_TAG_DOIT) == 0) {
584                                 build_animdata(obdata);
585                         }
586                         break;
587                 }
588         }
589 }
590
591 void DepsgraphNodeBuilder::build_object_transform(Object *object)
592 {
593         OperationDepsNode *op_node;
594         Scene *scene_cow = get_cow_datablock(scene_);
595         Object *ob_cow = get_cow_datablock(object);
596
597         /* local transforms (from transform channels - loc/rot/scale + deltas) */
598         op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
599                                      function_bind(BKE_object_eval_local_transform,
600                                                    _1,
601                                                    ob_cow),
602                                      DEG_OPCODE_TRANSFORM_LOCAL);
603         op_node->set_as_entry();
604
605         /* object parent */
606         if (object->parent != NULL) {
607                 add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
608                                    function_bind(BKE_object_eval_parent,
609                                                  _1,
610                                                  scene_cow,
611                                                  ob_cow),
612                                    DEG_OPCODE_TRANSFORM_PARENT);
613         }
614
615         /* object constraints */
616         if (object->constraints.first != NULL) {
617                 build_object_constraints(object);
618         }
619
620         /* Rest of transformation update. */
621         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
622                            function_bind(BKE_object_eval_uber_transform,
623                                          _1,
624                                          ob_cow),
625                            DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
626
627         /* object transform is done */
628         op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
629                                      function_bind(BKE_object_eval_done,
630                                                    _1,
631                                                    ob_cow),
632                                      DEG_OPCODE_TRANSFORM_FINAL);
633         op_node->set_as_exit();
634 }
635
636 /**
637  * Constraints Graph Notes
638  *
639  * For constraints, we currently only add a operation node to the Transform
640  * or Bone components (depending on whichever type of owner we have).
641  * This represents the entire constraints stack, which is for now just
642  * executed as a single monolithic block. At least initially, this should
643  * be sufficient for ensuring that the porting/refactoring process remains
644  * manageable.
645  *
646  * However, when the time comes for developing "node-based" constraints,
647  * we'll need to split this up into pre/post nodes for "constraint stack
648  * evaluation" + operation nodes for each constraint (i.e. the contents
649  * of the loop body used in the current "solve_constraints()" operation).
650  *
651  * -- Aligorith, August 2013
652  */
653 void DepsgraphNodeBuilder::build_object_constraints(Object *object)
654 {
655         /* create node for constraint stack */
656         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
657                            function_bind(BKE_object_eval_constraints,
658                                          _1,
659                                          get_cow_datablock(scene_),
660                                          get_cow_datablock(object)),
661                            DEG_OPCODE_TRANSFORM_CONSTRAINTS);
662 }
663
664 /**
665  * Build graph nodes for AnimData block
666  * \param id: ID-Block which hosts the AnimData
667  */
668 void DepsgraphNodeBuilder::build_animdata(ID *id)
669 {
670         AnimData *adt = BKE_animdata_from_id(id);
671         if (adt == NULL) {
672                 return;
673         }
674
675         /* animation */
676         if (adt->action || adt->nla_tracks.first || adt->drivers.first) {
677                 (void) add_id_node(id);
678                 ID *id_cow = get_cow_id(id);
679
680                 // XXX: Hook up specific update callbacks for special properties which
681                 // may need it...
682
683                 /* actions and NLA - as a single unit for now, as it gets complicated to
684                  * schedule otherwise.
685                  */
686                 if ((adt->action) || (adt->nla_tracks.first)) {
687                         /* create the node */
688                         add_operation_node(id, DEG_NODE_TYPE_ANIMATION,
689                                            function_bind(BKE_animsys_eval_animdata,
690                                                          _1,
691                                                          id_cow),
692                                            DEG_OPCODE_ANIMATION,
693                                            id->name);
694
695                         /* TODO: for each channel affected, we might also want to add some
696                          * support for running RNA update callbacks on them
697                          * (which will be needed for proper handling of drivers later)
698                          */
699                 }
700
701                 /* drivers */
702                 BLI_LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
703                         /* create driver */
704                         build_driver(id, fcu);
705                 }
706         }
707 }
708
709 /**
710  * Build graph node(s) for Driver
711  * \param id: ID-Block that driver is attached to
712  * \param fcu: Driver-FCurve
713  */
714 OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu)
715 {
716         ID *id_cow = get_cow_id(id);
717
718         /* Create data node for this driver */
719         /* TODO(sergey): Avoid creating same operation multiple times,
720          * in the future we need to avoid lookup of the operation as well
721          * and use some tagging magic instead.
722          */
723         OperationDepsNode *driver_op = find_operation_node(
724                 id,
725                 DEG_NODE_TYPE_PARAMETERS,
726                 DEG_OPCODE_DRIVER,
727                 fcu->rna_path ? fcu->rna_path : "",
728                 fcu->array_index);
729
730         if (driver_op == NULL) {
731                 /* TODO(sergey): Shall we use COW of fcu itself here? */
732                 driver_op = add_operation_node(id,
733                                                DEG_NODE_TYPE_PARAMETERS,
734                                                function_bind(BKE_animsys_eval_driver,
735                                                              _1,
736                                                              id_cow,
737                                                              fcu),
738                                                DEG_OPCODE_DRIVER,
739                                                fcu->rna_path ? fcu->rna_path : "",
740                                                fcu->array_index);
741         }
742
743         /* return driver node created */
744         return driver_op;
745 }
746
747 /* Recursively build graph for world */
748 void DepsgraphNodeBuilder::build_world(World *world)
749 {
750         ID *world_id = &world->id;
751         if (world_id->tag & LIB_TAG_DOIT) {
752                 return;
753         }
754         /* Animation. */
755         build_animdata(world_id);
756         /* world itself */
757         add_operation_node(world_id,
758                            DEG_NODE_TYPE_SHADING,
759                            function_bind(BKE_world_eval,
760                                          _1,
761                                          get_cow_datablock(world)),
762                            DEG_OPCODE_WORLD_UPDATE);
763         /* textures */
764         build_texture_stack(world->mtex);
765         /* world's nodetree */
766         if (world->nodetree != NULL) {
767                 build_nodetree(world->nodetree);
768         }
769 }
770
771 /* Rigidbody Simulation - Scene Level */
772 void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
773 {
774         RigidBodyWorld *rbw = scene->rigidbody_world;
775         Scene *scene_cow = get_cow_datablock(scene);
776
777         /**
778          * Rigidbody Simulation Nodes
779          * ==========================
780          *
781          * There are 3 nodes related to Rigidbody Simulation:
782          * 1) "Initialize/Rebuild World" - this is called sparingly, only when the
783          *    simulation needs to be rebuilt (mainly after file reload, or moving
784          *    back to start frame)
785          * 2) "Do Simulation" - perform a simulation step - interleaved between the
786          *    evaluation steps for clusters of objects (i.e. between those affected
787          *    and/or not affected by the sim for instance).
788          *
789          * 3) "Pull Results" - grab the specific transforms applied for a specific
790          *    object - performed as part of object's transform-stack building.
791          */
792
793         /* Create nodes --------------------------------------------------------- */
794
795         /* XXX: is this the right component, or do we want to use another one
796          * instead?
797          */
798
799         /* init/rebuild operation */
800         /*OperationDepsNode *init_node =*/ add_operation_node(
801                 &scene->id, DEG_NODE_TYPE_TRANSFORM,
802                 function_bind(BKE_rigidbody_rebuild_sim, _1, scene_cow),
803                 DEG_OPCODE_RIGIDBODY_REBUILD);
804
805         /* do-sim operation */
806         // XXX: what happens if we need to split into several groups?
807         OperationDepsNode *sim_node = add_operation_node(
808                 &scene->id, DEG_NODE_TYPE_TRANSFORM,
809                 function_bind(BKE_rigidbody_eval_simulation, _1, scene_cow),
810                 DEG_OPCODE_RIGIDBODY_SIM);
811
812         /* XXX: For now, the sim node is the only one that really matters here.
813          * If any other sims get added later, we may have to remove these hacks...
814          */
815         sim_node->owner->entry_operation = sim_node;
816         sim_node->owner->exit_operation  = sim_node;
817
818         /* objects - simulation participants */
819         if (rbw->group) {
820                 BLI_LISTBASE_FOREACH (Base *, base, &rbw->group->view_layer->object_bases) {
821                         Object *object = base->object;
822
823                         if (!object || (object->type != OB_MESH))
824                                 continue;
825
826                         /* 2) create operation for flushing results */
827                         /* object's transform component - where the rigidbody operation
828                          * lives. */
829                         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
830                                            function_bind(
831                                                    BKE_rigidbody_object_sync_transforms,
832                                                    _1,
833                                                    scene_cow,
834                                                    get_cow_datablock(object)),
835                                            DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
836                 }
837         }
838 }
839
840 void DepsgraphNodeBuilder::build_particles(Object *object)
841 {
842         /**
843          * Particle Systems Nodes
844          * ======================
845          *
846          * There are two types of nodes associated with representing
847          * particle systems:
848          *  1) Component (EVAL_PARTICLES) - This is the particle-system
849          *     evaluation context for an object. It acts as the container
850          *     for all the nodes associated with a particular set of particle
851          *     systems.
852          *  2) Particle System Eval Operation - This operation node acts as a
853          *     blackbox evaluation step for one particle system referenced by
854          *     the particle systems stack. All dependencies link to this operation.
855          */
856
857         /* component for all particle systems */
858         ComponentDepsNode *psys_comp =
859                 add_component_node(&object->id, DEG_NODE_TYPE_EVAL_PARTICLES);
860
861         /* TODO(sergey): Need to get COW of PSYS. */
862         Scene *scene_cow = get_cow_datablock(scene_);
863         Object *ob_cow = get_cow_datablock(object);
864
865         add_operation_node(psys_comp,
866                            function_bind(BKE_particle_system_eval_init,
867                                          _1,
868                                          scene_cow,
869                                          ob_cow),
870                            DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
871
872         /* particle systems */
873         BLI_LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
874                 ParticleSettings *part = psys->part;
875
876                 /* Build particle settings operations.
877                  *
878                  * NOTE: The call itself ensures settings are only build once.
879                  */
880                 build_particle_settings(part);
881
882                 /* Update on particle settings change. */
883                 add_operation_node(psys_comp,
884                                    function_bind(BKE_particle_system_settings_eval,
885                                                  _1,
886                                                  psys),
887                                    DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
888                                    psys->name);
889
890                 /* Particle system evaluation. */
891                 add_operation_node(psys_comp,
892                                    NULL,
893                                    DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
894                                    psys->name);
895         }
896
897         /* TODO(sergey): Do we need a point cache operations here? */
898 }
899
900 void DepsgraphNodeBuilder::build_particle_settings(ParticleSettings *part) {
901         ID *part_id = &part->id;
902         if (part_id->tag & LIB_TAG_DOIT) {
903                 return;
904         }
905         part_id->tag |= LIB_TAG_DOIT;
906         /* Animation data. */
907         build_animdata(part_id);
908         /* Parameters change. */
909         add_operation_node(part_id,
910                            DEG_NODE_TYPE_PARAMETERS,
911                            NULL,
912                            DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
913         add_operation_node(part_id,
914                            DEG_NODE_TYPE_PARAMETERS,
915                            function_bind(BKE_particle_system_settings_recalc_clear,
916                                          _1,
917                                          part),
918                            DEG_OPCODE_PARTICLE_SETTINGS_RECALC_CLEAR);
919 }
920
921 void DepsgraphNodeBuilder::build_cloth(Object *object)
922 {
923         Scene *scene_cow = get_cow_datablock(scene_);
924         Object *object_cow = get_cow_datablock(object);
925         add_operation_node(&object->id,
926                            DEG_NODE_TYPE_CACHE,
927                            function_bind(BKE_object_eval_cloth,
928                                          _1,
929                                          scene_cow,
930                                          object_cow),
931                            DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER);
932 }
933
934 /* Shapekeys */
935 void DepsgraphNodeBuilder::build_shapekeys(Key *key)
936 {
937         build_animdata(&key->id);
938         add_operation_node(&key->id,
939                            DEG_NODE_TYPE_GEOMETRY,
940                            NULL,
941                            DEG_OPCODE_GEOMETRY_SHAPEKEY);
942 }
943
944 /* ObData Geometry Evaluation */
945 // XXX: what happens if the datablock is shared!
946 void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
947 {
948         OperationDepsNode *op_node;
949         Scene *scene_cow = get_cow_datablock(scene_);
950         Object *object_cow = get_cow_datablock(object);
951
952         /* TODO(sergey): This way using this object's properties as driver target
953          * works fine.
954          *
955          * Does this depend on other nodes?
956          */
957         op_node = add_operation_node(&object->id,
958                                      DEG_NODE_TYPE_PARAMETERS,
959                                      NULL,
960                                      DEG_OPCODE_PARAMETERS_EVAL);
961         op_node->set_as_exit();
962
963         /* Temporary uber-update node, which does everything.
964          * It is for the being we're porting old dependencies into the new system.
965          * We'll get rid of this node as soon as all the granular update functions
966          * are filled in.
967          *
968          * TODO(sergey): Get rid of this node.
969          */
970         op_node = add_operation_node(&object->id,
971                                      DEG_NODE_TYPE_GEOMETRY,
972                                      function_bind(BKE_object_eval_uber_data,
973                                                    _1,
974                                                    scene_cow,
975                                                    object_cow),
976                                      DEG_OPCODE_GEOMETRY_UBEREVAL);
977         op_node->set_as_exit();
978
979         op_node = add_operation_node(&object->id,
980                                      DEG_NODE_TYPE_GEOMETRY,
981                                      NULL,
982                                      DEG_OPCODE_PLACEHOLDER,
983                                      "Eval Init");
984         op_node->set_as_entry();
985
986         // TODO: "Done" operation
987
988         /* Cloth modifier. */
989         BLI_LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
990                 if (md->type == eModifierType_Cloth) {
991                         build_cloth(object);
992                 }
993         }
994
995         /* materials */
996         if (object->totcol != 0) {
997                 if (object->type == OB_MESH) {
998                         add_operation_node(&object->id,
999                                            DEG_NODE_TYPE_SHADING,
1000                                            function_bind(BKE_object_eval_update_shading,
1001                                                          _1,
1002                                                          object_cow),
1003                                            DEG_OPCODE_SHADING);
1004                 }
1005
1006                 for (int a = 1; a <= object->totcol; a++) {
1007                         Material *ma = give_current_material(object, a);
1008                         if (ma != NULL) {
1009                                 build_material(ma);
1010                         }
1011                 }
1012         }
1013
1014         /* geometry collision */
1015         if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1016                 // add geometry collider relations
1017         }
1018
1019         ID *obdata = (ID *)object->data;
1020         if (obdata->tag & LIB_TAG_DOIT) {
1021                 return;
1022         }
1023         obdata->tag |= LIB_TAG_DOIT;
1024         /* Make sure we've got an ID node before requesting CoW pointer. */
1025         (void) add_id_node((ID *)obdata);
1026         ID *obdata_cow = get_cow_id(obdata);
1027
1028         /* ShapeKeys */
1029         Key *key = BKE_key_from_object(object);
1030         if (key) {
1031                 build_shapekeys(key);
1032         }
1033
1034         build_animdata(obdata);
1035
1036         /* Nodes for result of obdata's evaluation, and geometry
1037          * evaluation on object.
1038          */
1039         switch (object->type) {
1040                 case OB_MESH:
1041                 {
1042                         //Mesh *me = (Mesh *)object->data;
1043
1044                         /* evaluation operations */
1045                         op_node = add_operation_node(obdata,
1046                                                      DEG_NODE_TYPE_GEOMETRY,
1047                                                      function_bind(BKE_mesh_eval_geometry,
1048                                                                    _1,
1049                                                                    (Mesh *)obdata_cow),
1050                                                      DEG_OPCODE_PLACEHOLDER,
1051                                                      "Geometry Eval");
1052                         op_node->set_as_entry();
1053                         break;
1054                 }
1055
1056                 case OB_MBALL:
1057                 {
1058                         Object *mom = BKE_mball_basis_find(scene_, object);
1059                         /* NOTE: Only the motherball gets evaluated, it's children are
1060                          * having empty placeholders for the correct relations being built.
1061                          */
1062                         if (mom == object) {
1063                                 /* metaball evaluation operations */
1064                                 op_node = add_operation_node(obdata,
1065                                                              DEG_NODE_TYPE_GEOMETRY,
1066                                                              function_bind(
1067                                                                      BKE_mball_eval_geometry,
1068                                                                      _1,
1069                                                                      (MetaBall *)obdata_cow),
1070                                                              DEG_OPCODE_PLACEHOLDER,
1071                                                              "Geometry Eval");
1072                         }
1073                         else {
1074                                 op_node = add_operation_node(obdata,
1075                                                              DEG_NODE_TYPE_GEOMETRY,
1076                                                              NULL,
1077                                                              DEG_OPCODE_PLACEHOLDER,
1078                                                              "Geometry Eval");
1079                                 op_node->set_as_entry();
1080                         }
1081                         break;
1082                 }
1083
1084                 case OB_CURVE:
1085                 case OB_SURF:
1086                 case OB_FONT:
1087                 {
1088                         /* Curve/nurms evaluation operations. */
1089                         /* - calculate curve geometry (including path) */
1090                         op_node = add_operation_node(obdata,
1091                                                      DEG_NODE_TYPE_GEOMETRY,
1092                                                      function_bind(BKE_curve_eval_geometry,
1093                                                                    _1,
1094                                                                    (Curve *)obdata_cow),
1095                                                                    DEG_OPCODE_PLACEHOLDER,
1096                                                                    "Geometry Eval");
1097                         op_node->set_as_entry();
1098                         /* Make sure objects used for bevel.taper are in the graph.
1099                          * NOTE: This objects might be not linked to the scene.
1100                          */
1101                         Curve *cu = (Curve *)obdata;
1102                         if (cu->bevobj != NULL) {
1103                                 build_object(NULL, cu->bevobj, DEG_ID_LINKED_INDIRECTLY);
1104                         }
1105                         if (cu->taperobj != NULL) {
1106                                 build_object(NULL, cu->taperobj, DEG_ID_LINKED_INDIRECTLY);
1107                         }
1108                         if (object->type == OB_FONT && cu->textoncurve != NULL) {
1109                                 build_object(NULL, cu->textoncurve, DEG_ID_LINKED_INDIRECTLY);
1110                         }
1111                         break;
1112                 }
1113
1114                 case OB_LATTICE:
1115                 {
1116                         /* Lattice evaluation operations. */
1117                         op_node = add_operation_node(obdata,
1118                                                      DEG_NODE_TYPE_GEOMETRY,
1119                                                      function_bind(BKE_lattice_eval_geometry,
1120                                                                    _1,
1121                                                                    (Lattice *)obdata_cow),
1122                                                                    DEG_OPCODE_PLACEHOLDER,
1123                                                                    "Geometry Eval");
1124                         op_node->set_as_entry();
1125                         break;
1126                 }
1127         }
1128
1129         op_node = add_operation_node(obdata, DEG_NODE_TYPE_GEOMETRY, NULL,
1130                                      DEG_OPCODE_PLACEHOLDER, "Eval Done");
1131         op_node->set_as_exit();
1132
1133         /* Parameters for driver sources. */
1134         add_operation_node(obdata,
1135                            DEG_NODE_TYPE_PARAMETERS,
1136                            NULL,
1137                            DEG_OPCODE_PARAMETERS_EVAL);
1138
1139         /* Batch cache. */
1140         add_operation_node(obdata,
1141                            DEG_NODE_TYPE_BATCH_CACHE,
1142                            function_bind(BKE_object_data_select_update,
1143                                          _1,
1144                                          obdata_cow),
1145                            DEG_OPCODE_GEOMETRY_SELECT_UPDATE);
1146 }
1147
1148 /* Cameras */
1149 void DepsgraphNodeBuilder::build_camera(Object *object)
1150 {
1151         /* Object itself. */
1152         add_operation_node(&object->id,
1153                            DEG_NODE_TYPE_PARAMETERS,
1154                            NULL,
1155                            DEG_OPCODE_PARAMETERS_EVAL,
1156                            "Camera Parameters");
1157
1158         /* Object data. */
1159         /* TODO: Link scene-camera links in somehow. */
1160         Camera *cam = (Camera *)object->data;
1161         ID *camera_id = &cam->id;
1162         if (camera_id->tag & LIB_TAG_DOIT) {
1163                 return;
1164         }
1165
1166         build_animdata(&cam->id);
1167
1168         add_operation_node(camera_id,
1169                            DEG_NODE_TYPE_PARAMETERS,
1170                            NULL,
1171                            DEG_OPCODE_PARAMETERS_EVAL);
1172 }
1173
1174 /* Lamps */
1175 void DepsgraphNodeBuilder::build_lamp(Object *object)
1176 {
1177         /* Object itself. */
1178         add_operation_node(&object->id,
1179                            DEG_NODE_TYPE_PARAMETERS,
1180                            NULL,
1181                            DEG_OPCODE_PARAMETERS_EVAL,
1182                            "Lamp Parameters");
1183
1184         /* Object data. */
1185         Lamp *la = (Lamp *)object->data;
1186         ID *lamp_id = &la->id;
1187         if (lamp_id->tag & LIB_TAG_DOIT) {
1188                 return;
1189         }
1190
1191         build_animdata(&la->id);
1192
1193         add_operation_node(lamp_id,
1194                            DEG_NODE_TYPE_PARAMETERS,
1195                            NULL,
1196                            DEG_OPCODE_PARAMETERS_EVAL);
1197
1198         /* lamp's nodetree */
1199         if (la->nodetree) {
1200                 build_nodetree(la->nodetree);
1201         }
1202
1203         /* textures */
1204         build_texture_stack(la->mtex);
1205 }
1206
1207 void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
1208 {
1209         if (ntree == NULL) {
1210                 return;
1211         }
1212         /* nodetree itself */
1213         ID *ntree_id = &ntree->id;
1214         add_id_node(ntree_id);
1215         bNodeTree *ntree_cow = get_cow_datablock(ntree);
1216         /* Animation, */
1217         build_animdata(ntree_id);
1218         /* Shading update. */
1219         add_operation_node(ntree_id,
1220                            DEG_NODE_TYPE_SHADING,
1221                            NULL,
1222                            DEG_OPCODE_MATERIAL_UPDATE);
1223         /* NOTE: We really pass original and CoW node trees here, this is how the
1224          * callback works. Ideally we need to find a better way for that.
1225          */
1226         add_operation_node(ntree_id,
1227                            DEG_NODE_TYPE_SHADING_PARAMETERS,
1228                            function_bind(BKE_nodetree_shading_params_eval,
1229                                          _1,
1230                                          ntree_cow,
1231                                          ntree),
1232                            DEG_OPCODE_MATERIAL_UPDATE);
1233         /* nodetree's nodes... */
1234         BLI_LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) {
1235                 ID *id = bnode->id;
1236                 if (id == NULL) {
1237                         continue;
1238                 }
1239                 ID_Type id_type = GS(id->name);
1240                 if (id_type == ID_MA) {
1241                         build_material((Material *)id);
1242                 }
1243                 else if (id_type == ID_TE) {
1244                         build_texture((Tex *)id);
1245                 }
1246                 else if (id_type == ID_IM) {
1247                         build_image((Image *)id);
1248                 }
1249                 else if (id_type == ID_OB) {
1250                         build_object(NULL, (Object *)id, DEG_ID_LINKED_INDIRECTLY);
1251                 }
1252                 else if (id_type == ID_SCE) {
1253                         /* Scenes are used by compositor trees, and handled by render
1254                          * pipeline. No need to build dependencies for them here.
1255                          */
1256                 }
1257                 else if (id_type == ID_TXT) {
1258                         /* Ignore script nodes. */
1259                 }
1260                 else if (bnode->type == NODE_GROUP) {
1261                         bNodeTree *group_ntree = (bNodeTree *)id;
1262                         if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) {
1263                                 build_nodetree(group_ntree);
1264                         }
1265                 }
1266                 else {
1267                         BLI_assert(!"Unknown ID type used for node");
1268                 }
1269         }
1270
1271         // TODO: link from nodetree to owner_component?
1272 }
1273
1274 /* Recursively build graph for material */
1275 void DepsgraphNodeBuilder::build_material(Material *material)
1276 {
1277         ID *material_id = &material->id;
1278         if (material_id->tag & LIB_TAG_DOIT) {
1279                 return;
1280         }
1281         material_id->tag |= LIB_TAG_DOIT;
1282         /* Material itself. */
1283         add_id_node(material_id);
1284         Material *material_cow = get_cow_datablock(material);
1285         /* Shading update. */
1286         add_operation_node(material_id,
1287                            DEG_NODE_TYPE_SHADING,
1288                            function_bind(BKE_material_eval,
1289                                          _1,
1290                                          material_cow),
1291                            DEG_OPCODE_MATERIAL_UPDATE);
1292         /* Material animation. */
1293         build_animdata(material_id);
1294         /* Textures. */
1295         build_texture_stack(material->mtex);
1296         /* Material's nodetree. */
1297         build_nodetree(material->nodetree);
1298 }
1299
1300 /* Texture-stack attached to some shading datablock */
1301 void DepsgraphNodeBuilder::build_texture_stack(MTex **texture_stack)
1302 {
1303         /* for now assume that all texture-stacks have same number of max items */
1304         for (int i = 0; i < MAX_MTEX; i++) {
1305                 MTex *mtex = texture_stack[i];
1306                 if (mtex && mtex->tex) {
1307                         build_texture(mtex->tex);
1308                 }
1309         }
1310 }
1311
1312 /* Recursively build graph for texture */
1313 void DepsgraphNodeBuilder::build_texture(Tex *tex)
1314 {
1315         ID *tex_id = &tex->id;
1316         if (tex_id->tag & LIB_TAG_DOIT) {
1317                 return;
1318         }
1319         tex_id->tag |= LIB_TAG_DOIT;
1320         /* Texture itself. */
1321         build_animdata(tex_id);
1322         /* Texture's nodetree. */
1323         build_nodetree(tex->nodetree);
1324         /* Special cases for different IDs which texture uses. */
1325         if (tex->type == TEX_IMAGE) {
1326                 if (tex->ima != NULL) {
1327                         build_image(tex->ima);
1328                 }
1329         }
1330 }
1331
1332 void DepsgraphNodeBuilder::build_image(Image *image) {
1333         ID *image_id = &image->id;
1334         if (image_id->tag & LIB_TAG_DOIT) {
1335                 return;
1336         }
1337         image_id->tag |= LIB_TAG_DOIT;
1338         /* Placeholder so we can add relations and tag ID node for update. */
1339         add_operation_node(image_id,
1340                            DEG_NODE_TYPE_PARAMETERS,
1341                            NULL,
1342                            DEG_OPCODE_PLACEHOLDER,
1343                            "Image Eval");
1344 }
1345
1346 void DepsgraphNodeBuilder::build_compositor(Scene *scene)
1347 {
1348         /* For now, just a plain wrapper? */
1349         // TODO: create compositing component?
1350         // XXX: component type undefined!
1351         //graph->get_node(&scene->id, NULL, DEG_NODE_TYPE_COMPOSITING, NULL);
1352
1353         /* for now, nodetrees are just parameters; compositing occurs in internals
1354          * of renderer...
1355          */
1356         add_component_node(&scene->id, DEG_NODE_TYPE_PARAMETERS);
1357         build_nodetree(scene->nodetree);
1358 }
1359
1360 void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd)
1361 {
1362         ID *gpd_id = &gpd->id;
1363
1364         /* TODO(sergey): what about multiple users of same datablock? This should
1365          * only get added once.
1366          */
1367
1368         /* The main reason Grease Pencil is included here is because the animation
1369          * (and drivers) need to be hosted somewhere.
1370          */
1371         build_animdata(gpd_id);
1372 }
1373
1374 void DepsgraphNodeBuilder::build_cachefile(CacheFile *cache_file)
1375 {
1376         ID *cache_file_id = &cache_file->id;
1377         /* Animation, */
1378         build_animdata(cache_file_id);
1379         /* Cache evaluation itself. */
1380         add_operation_node(cache_file_id, DEG_NODE_TYPE_CACHE, NULL,
1381                            DEG_OPCODE_PLACEHOLDER, "Cache File Update");
1382 }
1383
1384 void DepsgraphNodeBuilder::build_mask(Mask *mask)
1385 {
1386         ID *mask_id = &mask->id;
1387         Mask *mask_cow = get_cow_datablock(mask);
1388         /* F-Curve based animation. */
1389         build_animdata(mask_id);
1390         /* Animation based on mask's shapes. */
1391         add_operation_node(mask_id,
1392                            DEG_NODE_TYPE_ANIMATION,
1393                            function_bind(BKE_mask_eval_animation, _1, mask_cow),
1394                            DEG_OPCODE_MASK_ANIMATION);
1395         /* Final mask evaluation. */
1396         add_operation_node(mask_id,
1397                            DEG_NODE_TYPE_PARAMETERS,
1398                            function_bind(BKE_mask_eval_update, _1, mask_cow),
1399                            DEG_OPCODE_MASK_EVAL);
1400 }
1401
1402 void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip)
1403 {
1404         ID *clip_id = &clip->id;
1405         MovieClip *clip_cow = get_cow_datablock(clip);
1406         /* Animation. */
1407         build_animdata(clip_id);
1408         /* Movie clip evaluation. */
1409         add_operation_node(clip_id,
1410                            DEG_NODE_TYPE_PARAMETERS,
1411                            function_bind(BKE_movieclip_eval_update, _1, clip_cow),
1412                            DEG_OPCODE_MOVIECLIP_EVAL);
1413 }
1414
1415 void DepsgraphNodeBuilder::build_lightprobe(Object *object)
1416 {
1417         LightProbe *probe = (LightProbe *)object->data;
1418         ID *probe_id = &probe->id;
1419         if (probe_id->tag & LIB_TAG_DOIT) {
1420                 return;
1421         }
1422         probe_id->tag |= LIB_TAG_DOIT;
1423         /* Placeholder so we can add relations and tag ID node for update. */
1424         add_operation_node(probe_id,
1425                            DEG_NODE_TYPE_PARAMETERS,
1426                            NULL,
1427                            DEG_OPCODE_PLACEHOLDER,
1428                            "LightProbe Eval");
1429         add_operation_node(&object->id,
1430                            DEG_NODE_TYPE_PARAMETERS,
1431                            NULL,
1432                            DEG_OPCODE_PLACEHOLDER,
1433                            "LightProbe Eval");
1434
1435         build_animdata(probe_id);
1436 }
1437
1438 }  // namespace DEG