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