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);
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 (GroupObject *, go, &group->gobject) {
432                 build_object(NULL, go->ob, DEG_ID_LINKED_INDIRECTLY);
433         }
434 }
435
436 void DepsgraphNodeBuilder::build_object(Base *base,
437                                         Object *object,
438                                         eDepsNode_LinkedState_Type linked_state)
439 {
440         /* Skip rest of components if the ID node was already there. */
441         if (object->id.tag & LIB_TAG_DOIT) {
442                 IDDepsNode *id_node = find_id_node(&object->id);
443                 /* We need to build some extra stuff if object becomes linked
444                  * directly.
445                  */
446                 if (id_node->linked_state == DEG_ID_LINKED_INDIRECTLY) {
447                         build_object_flags(base, object, linked_state);
448                 }
449                 id_node->linked_state = max(id_node->linked_state, linked_state);
450                 return;
451         }
452         object->id.tag |= LIB_TAG_DOIT;
453         /* Create ID node for object and begin init. */
454         IDDepsNode *id_node = add_id_node(&object->id);
455         id_node->linked_state = linked_state;
456         object->customdata_mask = 0;
457         /* Various flags, flushing from bases/collections. */
458         build_object_flags(base, object, linked_state);
459         /* Transform. */
460         build_object_transform(object);
461         /* Parent. */
462         if (object->parent != NULL) {
463                 build_object(NULL, object->parent, DEG_ID_LINKED_INDIRECTLY);
464         }
465         /* Modifiers. */
466         if (object->modifiers.first != NULL) {
467                 BuilderWalkUserData data;
468                 data.builder = this;
469                 modifiers_foreachObjectLink(object, modifier_walk, &data);
470         }
471         /* Constraints. */
472         if (object->constraints.first != NULL) {
473                 BuilderWalkUserData data;
474                 data.builder = this;
475                 BKE_constraints_id_loop(&object->constraints, constraint_walk, &data);
476         }
477         /* Object data. */
478         build_object_data(object);
479         /* Build animation data,
480          *
481          * Do it now because it's possible object data will affect
482          * on object's level animation, for example in case of rebuilding
483          * pose for proxy.
484          */
485         build_animdata(&object->id);
486         /* Particle systems. */
487         if (object->particlesystem.first != NULL) {
488                 build_particles(object);
489         }
490         /* Grease pencil. */
491         if (object->gpd != NULL) {
492                 build_gpencil(object->gpd);
493         }
494         /* Object that this is a proxy for. */
495         if (object->proxy) {
496                 object->proxy->proxy_from = object;
497                 build_object(NULL, object->proxy, DEG_ID_LINKED_INDIRECTLY);
498         }
499         /* Object dupligroup. */
500         if (object->dup_group != NULL) {
501                 build_group(object->dup_group);
502         }
503 }
504
505 void DepsgraphNodeBuilder::build_object_flags(
506         Base *base,
507         Object *object,
508         eDepsNode_LinkedState_Type linked_state)
509 {
510         if (base == NULL) {
511                 return;
512         }
513         /* TODO(sergey): Is this really best component to be used? */
514         Object *object_cow = get_cow_datablock(object);
515         const bool is_from_set = (linked_state == DEG_ID_LINKED_VIA_SET);
516         add_operation_node(&object->id,
517                            DEG_NODE_TYPE_LAYER_COLLECTIONS,
518                            function_bind(BKE_object_eval_flush_base_flags,
519                                          _1, object_cow, base, is_from_set),
520                            DEG_OPCODE_OBJECT_BASE_FLAGS);
521 }
522
523 void DepsgraphNodeBuilder::build_object_data(Object *object)
524 {
525         if (object->data == NULL) {
526                 return;
527         }
528         IDDepsNode *id_node = graph_->find_id_node(&object->id);
529         /* type-specific data. */
530         switch (object->type) {
531                 case OB_MESH:
532                 case OB_CURVE:
533                 case OB_FONT:
534                 case OB_SURF:
535                 case OB_MBALL:
536                 case OB_LATTICE:
537                         build_obdata_geom(object);
538                         /* TODO(sergey): Only for until we support granular
539                          * update of curves.
540                          */
541                         if (object->type == OB_FONT) {
542                                 Curve *curve = (Curve *)object->data;
543                                 if (curve->textoncurve) {
544                                         id_node->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
545                                 }
546                         }
547                         break;
548                 case OB_ARMATURE:
549                         if (ID_IS_LINKED(object) && object->proxy_from != NULL) {
550                                 build_proxy_rig(object);
551                         }
552                         else {
553                                 build_rig(object);
554                         }
555                         break;
556                 case OB_LAMP:
557                         build_lamp(object);
558                         break;
559                 case OB_CAMERA:
560                         build_camera(object);
561                         break;
562                 case OB_LIGHTPROBE:
563                         build_lightprobe(object);
564                         break;
565                 default:
566                 {
567                         ID *obdata = (ID *)object->data;
568                         if ((obdata->tag & LIB_TAG_DOIT) == 0) {
569                                 build_animdata(obdata);
570                         }
571                         break;
572                 }
573         }
574 }
575
576 void DepsgraphNodeBuilder::build_object_transform(Object *object)
577 {
578         OperationDepsNode *op_node;
579         Scene *scene_cow = get_cow_datablock(scene_);
580         Object *ob_cow = get_cow_datablock(object);
581
582         /* local transforms (from transform channels - loc/rot/scale + deltas) */
583         op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
584                                      function_bind(BKE_object_eval_local_transform,
585                                                    _1,
586                                                    ob_cow),
587                                      DEG_OPCODE_TRANSFORM_LOCAL);
588         op_node->set_as_entry();
589
590         /* object parent */
591         if (object->parent != NULL) {
592                 add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
593                                    function_bind(BKE_object_eval_parent,
594                                                  _1,
595                                                  scene_cow,
596                                                  ob_cow),
597                                    DEG_OPCODE_TRANSFORM_PARENT);
598         }
599
600         /* object constraints */
601         if (object->constraints.first != NULL) {
602                 build_object_constraints(object);
603         }
604
605         /* Rest of transformation update. */
606         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
607                            function_bind(BKE_object_eval_uber_transform,
608                                          _1,
609                                          ob_cow),
610                            DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
611
612         /* object transform is done */
613         op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
614                                      function_bind(BKE_object_eval_done,
615                                                    _1,
616                                                    ob_cow),
617                                      DEG_OPCODE_TRANSFORM_FINAL);
618         op_node->set_as_exit();
619 }
620
621 /**
622  * Constraints Graph Notes
623  *
624  * For constraints, we currently only add a operation node to the Transform
625  * or Bone components (depending on whichever type of owner we have).
626  * This represents the entire constraints stack, which is for now just
627  * executed as a single monolithic block. At least initially, this should
628  * be sufficient for ensuring that the porting/refactoring process remains
629  * manageable.
630  *
631  * However, when the time comes for developing "node-based" constraints,
632  * we'll need to split this up into pre/post nodes for "constraint stack
633  * evaluation" + operation nodes for each constraint (i.e. the contents
634  * of the loop body used in the current "solve_constraints()" operation).
635  *
636  * -- Aligorith, August 2013
637  */
638 void DepsgraphNodeBuilder::build_object_constraints(Object *object)
639 {
640         /* create node for constraint stack */
641         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
642                            function_bind(BKE_object_eval_constraints,
643                                          _1,
644                                          get_cow_datablock(scene_),
645                                          get_cow_datablock(object)),
646                            DEG_OPCODE_TRANSFORM_CONSTRAINTS);
647 }
648
649 /**
650  * Build graph nodes for AnimData block
651  * \param id: ID-Block which hosts the AnimData
652  */
653 void DepsgraphNodeBuilder::build_animdata(ID *id)
654 {
655         AnimData *adt = BKE_animdata_from_id(id);
656         if (adt == NULL) {
657                 return;
658         }
659
660         /* animation */
661         if (adt->action || adt->nla_tracks.first || adt->drivers.first) {
662                 (void) add_id_node(id);
663                 ID *id_cow = get_cow_id(id);
664
665                 // XXX: Hook up specific update callbacks for special properties which
666                 // may need it...
667
668                 /* actions and NLA - as a single unit for now, as it gets complicated to
669                  * schedule otherwise.
670                  */
671                 if ((adt->action) || (adt->nla_tracks.first)) {
672                         /* create the node */
673                         add_operation_node(id, DEG_NODE_TYPE_ANIMATION,
674                                            function_bind(BKE_animsys_eval_animdata,
675                                                          _1,
676                                                          id_cow),
677                                            DEG_OPCODE_ANIMATION,
678                                            id->name);
679
680                         /* TODO: for each channel affected, we might also want to add some
681                          * support for running RNA update callbacks on them
682                          * (which will be needed for proper handling of drivers later)
683                          */
684                 }
685
686                 /* drivers */
687                 LINKLIST_FOREACH (FCurve *, fcu, &adt->drivers) {
688                         /* create driver */
689                         build_driver(id, fcu);
690                 }
691         }
692 }
693
694 /**
695  * Build graph node(s) for Driver
696  * \param id: ID-Block that driver is attached to
697  * \param fcu: Driver-FCurve
698  */
699 OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu)
700 {
701         ID *id_cow = get_cow_id(id);
702
703         /* Create data node for this driver */
704         /* TODO(sergey): Avoid creating same operation multiple times,
705          * in the future we need to avoid lookup of the operation as well
706          * and use some tagging magic instead.
707          */
708         OperationDepsNode *driver_op = find_operation_node(
709                 id,
710                 DEG_NODE_TYPE_PARAMETERS,
711                 DEG_OPCODE_DRIVER,
712                 fcu->rna_path ? fcu->rna_path : "",
713                 fcu->array_index);
714
715         if (driver_op == NULL) {
716                 /* TODO(sergey): Shall we use COW of fcu itself here? */
717                 driver_op = add_operation_node(id,
718                                                DEG_NODE_TYPE_PARAMETERS,
719                                                function_bind(BKE_animsys_eval_driver,
720                                                              _1,
721                                                              id_cow,
722                                                              fcu),
723                                                DEG_OPCODE_DRIVER,
724                                                fcu->rna_path ? fcu->rna_path : "",
725                                                fcu->array_index);
726         }
727
728         /* return driver node created */
729         return driver_op;
730 }
731
732 /* Recursively build graph for world */
733 void DepsgraphNodeBuilder::build_world(World *world)
734 {
735         ID *world_id = &world->id;
736         if (world_id->tag & LIB_TAG_DOIT) {
737                 return;
738         }
739         /* Animation. */
740         build_animdata(world_id);
741         /* world itself */
742         add_operation_node(world_id,
743                            DEG_NODE_TYPE_SHADING,
744                            function_bind(BKE_world_eval,
745                                          _1,
746                                          get_cow_datablock(world)),
747                            DEG_OPCODE_WORLD_UPDATE);
748         /* textures */
749         build_texture_stack(world->mtex);
750         /* world's nodetree */
751         if (world->nodetree != NULL) {
752                 build_nodetree(world->nodetree);
753         }
754 }
755
756 /* Rigidbody Simulation - Scene Level */
757 void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
758 {
759         RigidBodyWorld *rbw = scene->rigidbody_world;
760         Scene *scene_cow = get_cow_datablock(scene);
761
762         /**
763          * Rigidbody Simulation Nodes
764          * ==========================
765          *
766          * There are 3 nodes related to Rigidbody Simulation:
767          * 1) "Initialize/Rebuild World" - this is called sparingly, only when the
768          *    simulation needs to be rebuilt (mainly after file reload, or moving
769          *    back to start frame)
770          * 2) "Do Simulation" - perform a simulation step - interleaved between the
771          *    evaluation steps for clusters of objects (i.e. between those affected
772          *    and/or not affected by the sim for instance).
773          *
774          * 3) "Pull Results" - grab the specific transforms applied for a specific
775          *    object - performed as part of object's transform-stack building.
776          */
777
778         /* Create nodes --------------------------------------------------------- */
779
780         /* XXX: is this the right component, or do we want to use another one
781          * instead?
782          */
783
784         /* init/rebuild operation */
785         /*OperationDepsNode *init_node =*/ add_operation_node(
786                 &scene->id, DEG_NODE_TYPE_TRANSFORM,
787                 function_bind(BKE_rigidbody_rebuild_sim, _1, scene_cow),
788                 DEG_OPCODE_RIGIDBODY_REBUILD);
789
790         /* do-sim operation */
791         // XXX: what happens if we need to split into several groups?
792         OperationDepsNode *sim_node = add_operation_node(
793                 &scene->id, DEG_NODE_TYPE_TRANSFORM,
794                 function_bind(BKE_rigidbody_eval_simulation, _1, scene_cow),
795                 DEG_OPCODE_RIGIDBODY_SIM);
796
797         /* XXX: For now, the sim node is the only one that really matters here.
798          * If any other sims get added later, we may have to remove these hacks...
799          */
800         sim_node->owner->entry_operation = sim_node;
801         sim_node->owner->exit_operation  = sim_node;
802
803         /* objects - simulation participants */
804         if (rbw->group) {
805                 LINKLIST_FOREACH (GroupObject *, go, &rbw->group->gobject) {
806                         Object *object = go->ob;
807
808                         if (!object || (object->type != OB_MESH))
809                                 continue;
810
811                         /* 2) create operation for flushing results */
812                         /* object's transform component - where the rigidbody operation
813                          * lives. */
814                         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
815                                            function_bind(
816                                                    BKE_rigidbody_object_sync_transforms,
817                                                    _1,
818                                                    scene_cow,
819                                                    get_cow_datablock(object)),
820                                            DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
821                 }
822         }
823 }
824
825 void DepsgraphNodeBuilder::build_particles(Object *object)
826 {
827         /**
828          * Particle Systems Nodes
829          * ======================
830          *
831          * There are two types of nodes associated with representing
832          * particle systems:
833          *  1) Component (EVAL_PARTICLES) - This is the particle-system
834          *     evaluation context for an object. It acts as the container
835          *     for all the nodes associated with a particular set of particle
836          *     systems.
837          *  2) Particle System Eval Operation - This operation node acts as a
838          *     blackbox evaluation step for one particle system referenced by
839          *     the particle systems stack. All dependencies link to this operation.
840          */
841
842         /* component for all particle systems */
843         ComponentDepsNode *psys_comp =
844                 add_component_node(&object->id, DEG_NODE_TYPE_EVAL_PARTICLES);
845
846         /* TODO(sergey): Need to get COW of PSYS. */
847         Scene *scene_cow = get_cow_datablock(scene_);
848         Object *ob_cow = get_cow_datablock(object);
849
850         add_operation_node(psys_comp,
851                            function_bind(BKE_particle_system_eval_init,
852                                          _1,
853                                          scene_cow,
854                                          ob_cow),
855                            DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
856
857         /* particle systems */
858         LINKLIST_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
859                 ParticleSettings *part = psys->part;
860
861                 /* Build particle settings operations.
862                  *
863                  * NOTE: The call itself ensures settings are only build once.
864                  */
865                 build_particle_settings(part);
866
867                 /* Update on particle settings change. */
868                 add_operation_node(psys_comp,
869                                    function_bind(BKE_particle_system_settings_eval,
870                                                  _1,
871                                                  psys),
872                                    DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
873                                    psys->name);
874
875                 /* Particle system evaluation. */
876                 add_operation_node(psys_comp,
877                                    NULL,
878                                    DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
879                                    psys->name);
880         }
881
882         /* TODO(sergey): Do we need a point cache operations here? */
883 }
884
885 void DepsgraphNodeBuilder::build_particle_settings(ParticleSettings *part) {
886         ID *part_id = &part->id;
887         if (part_id->tag & LIB_TAG_DOIT) {
888                 return;
889         }
890         part_id->tag |= LIB_TAG_DOIT;
891         /* Animation data. */
892         build_animdata(part_id);
893         /* Parameters change. */
894         add_operation_node(part_id,
895                            DEG_NODE_TYPE_PARAMETERS,
896                            NULL,
897                            DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
898         add_operation_node(part_id,
899                            DEG_NODE_TYPE_PARAMETERS,
900                            function_bind(BKE_particle_system_settings_recalc_clear,
901                                          _1,
902                                          part),
903                            DEG_OPCODE_PARTICLE_SETTINGS_RECALC_CLEAR);
904 }
905
906 void DepsgraphNodeBuilder::build_cloth(Object *object)
907 {
908         Scene *scene_cow = get_cow_datablock(scene_);
909         Object *object_cow = get_cow_datablock(object);
910         add_operation_node(&object->id,
911                            DEG_NODE_TYPE_CACHE,
912                            function_bind(BKE_object_eval_cloth,
913                                          _1,
914                                          scene_cow,
915                                          object_cow),
916                            DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER);
917 }
918
919 /* Shapekeys */
920 void DepsgraphNodeBuilder::build_shapekeys(Key *key)
921 {
922         build_animdata(&key->id);
923         add_operation_node(&key->id,
924                            DEG_NODE_TYPE_GEOMETRY,
925                            NULL,
926                            DEG_OPCODE_GEOMETRY_SHAPEKEY);
927 }
928
929 /* ObData Geometry Evaluation */
930 // XXX: what happens if the datablock is shared!
931 void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
932 {
933         OperationDepsNode *op_node;
934         Scene *scene_cow = get_cow_datablock(scene_);
935         Object *object_cow = get_cow_datablock(object);
936
937         /* TODO(sergey): This way using this object's properties as driver target
938          * works fine.
939          *
940          * Does this depend on other nodes?
941          */
942         op_node = add_operation_node(&object->id,
943                                      DEG_NODE_TYPE_PARAMETERS,
944                                      NULL,
945                                      DEG_OPCODE_PARAMETERS_EVAL);
946         op_node->set_as_exit();
947
948         /* Temporary uber-update node, which does everything.
949          * It is for the being we're porting old dependencies into the new system.
950          * We'll get rid of this node as soon as all the granular update functions
951          * are filled in.
952          *
953          * TODO(sergey): Get rid of this node.
954          */
955         op_node = add_operation_node(&object->id,
956                                      DEG_NODE_TYPE_GEOMETRY,
957                                      function_bind(BKE_object_eval_uber_data,
958                                                    _1,
959                                                    scene_cow,
960                                                    object_cow),
961                                      DEG_OPCODE_GEOMETRY_UBEREVAL);
962         op_node->set_as_exit();
963
964         op_node = add_operation_node(&object->id,
965                                      DEG_NODE_TYPE_GEOMETRY,
966                                      NULL,
967                                      DEG_OPCODE_PLACEHOLDER,
968                                      "Eval Init");
969         op_node->set_as_entry();
970
971         // TODO: "Done" operation
972
973         /* Cloyth modifier. */
974         LINKLIST_FOREACH (ModifierData *, md, &object->modifiers) {
975                 if (md->type == eModifierType_Cloth) {
976                         build_cloth(object);
977                 }
978         }
979
980         /* materials */
981         if (object->totcol != 0) {
982                 if (object->type == OB_MESH) {
983                         add_operation_node(&object->id,
984                                            DEG_NODE_TYPE_SHADING,
985                                            function_bind(BKE_object_eval_update_shading,
986                                                          _1,
987                                                          object_cow),
988                                            DEG_OPCODE_SHADING);
989                 }
990
991                 for (int a = 1; a <= object->totcol; a++) {
992                         Material *ma = give_current_material(object, a);
993                         if (ma != NULL) {
994                                 build_material(ma);
995                         }
996                 }
997         }
998
999         /* geometry collision */
1000         if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1001                 // add geometry collider relations
1002         }
1003
1004         ID *obdata = (ID *)object->data;
1005         if (obdata->tag & LIB_TAG_DOIT) {
1006                 return;
1007         }
1008         obdata->tag |= LIB_TAG_DOIT;
1009         /* Make sure we've got an ID node before requesting CoW pointer. */
1010         (void) add_id_node((ID *)obdata);
1011         ID *obdata_cow = get_cow_id(obdata);
1012
1013         /* ShapeKeys */
1014         Key *key = BKE_key_from_object(object);
1015         if (key) {
1016                 build_shapekeys(key);
1017         }
1018
1019         build_animdata(obdata);
1020
1021         /* Nodes for result of obdata's evaluation, and geometry
1022          * evaluation on object.
1023          */
1024         switch (object->type) {
1025                 case OB_MESH:
1026                 {
1027                         //Mesh *me = (Mesh *)object->data;
1028
1029                         /* evaluation operations */
1030                         op_node = add_operation_node(obdata,
1031                                                      DEG_NODE_TYPE_GEOMETRY,
1032                                                      function_bind(BKE_mesh_eval_geometry,
1033                                                                    _1,
1034                                                                    (Mesh *)obdata_cow),
1035                                                      DEG_OPCODE_PLACEHOLDER,
1036                                                      "Geometry Eval");
1037                         op_node->set_as_entry();
1038                         break;
1039                 }
1040
1041                 case OB_MBALL:
1042                 {
1043                         Object *mom = BKE_mball_basis_find(scene_, object);
1044                         /* NOTE: Only the motherball gets evaluated, it's children are
1045                          * having empty placeholders for the correct relations being built.
1046                          */
1047                         if (mom == object) {
1048                                 /* metaball evaluation operations */
1049                                 op_node = add_operation_node(obdata,
1050                                                              DEG_NODE_TYPE_GEOMETRY,
1051                                                              function_bind(
1052                                                                      BKE_mball_eval_geometry,
1053                                                                      _1,
1054                                                                      (MetaBall *)obdata_cow),
1055                                                              DEG_OPCODE_PLACEHOLDER,
1056                                                              "Geometry Eval");
1057                         }
1058                         else {
1059                                 op_node = add_operation_node(obdata,
1060                                                              DEG_NODE_TYPE_GEOMETRY,
1061                                                              NULL,
1062                                                              DEG_OPCODE_PLACEHOLDER,
1063                                                              "Geometry Eval");
1064                                 op_node->set_as_entry();
1065                         }
1066                         break;
1067                 }
1068
1069                 case OB_CURVE:
1070                 case OB_SURF:
1071                 case OB_FONT:
1072                 {
1073                         /* Curve/nurms evaluation operations. */
1074                         /* - calculate curve geometry (including path) */
1075                         op_node = add_operation_node(obdata,
1076                                                      DEG_NODE_TYPE_GEOMETRY,
1077                                                      function_bind(BKE_curve_eval_geometry,
1078                                                                    _1,
1079                                                                    (Curve *)obdata_cow),
1080                                                                    DEG_OPCODE_PLACEHOLDER,
1081                                                                    "Geometry Eval");
1082                         op_node->set_as_entry();
1083                         /* Make sure objects used for bevel.taper are in the graph.
1084                          * NOTE: This objects might be not linked to the scene.
1085                          */
1086                         Curve *cu = (Curve *)obdata;
1087                         if (cu->bevobj != NULL) {
1088                                 build_object(NULL, cu->bevobj, DEG_ID_LINKED_INDIRECTLY);
1089                         }
1090                         if (cu->taperobj != NULL) {
1091                                 build_object(NULL, cu->taperobj, DEG_ID_LINKED_INDIRECTLY);
1092                         }
1093                         if (object->type == OB_FONT && cu->textoncurve != NULL) {
1094                                 build_object(NULL, cu->textoncurve, DEG_ID_LINKED_INDIRECTLY);
1095                         }
1096                         break;
1097                 }
1098
1099                 case OB_LATTICE:
1100                 {
1101                         /* Lattice evaluation operations. */
1102                         op_node = add_operation_node(obdata,
1103                                                      DEG_NODE_TYPE_GEOMETRY,
1104                                                      function_bind(BKE_lattice_eval_geometry,
1105                                                                    _1,
1106                                                                    (Lattice *)obdata_cow),
1107                                                                    DEG_OPCODE_PLACEHOLDER,
1108                                                                    "Geometry Eval");
1109                         op_node->set_as_entry();
1110                         break;
1111                 }
1112         }
1113
1114         op_node = add_operation_node(obdata, DEG_NODE_TYPE_GEOMETRY, NULL,
1115                                      DEG_OPCODE_PLACEHOLDER, "Eval Done");
1116         op_node->set_as_exit();
1117
1118         /* Parameters for driver sources. */
1119         add_operation_node(obdata,
1120                            DEG_NODE_TYPE_PARAMETERS,
1121                            NULL,
1122                            DEG_OPCODE_PARAMETERS_EVAL);
1123
1124         /* Batch cache. */
1125         add_operation_node(obdata,
1126                            DEG_NODE_TYPE_BATCH_CACHE,
1127                            function_bind(BKE_object_data_select_update,
1128                                          _1,
1129                                          obdata_cow),
1130                            DEG_OPCODE_GEOMETRY_SELECT_UPDATE);
1131 }
1132
1133 /* Cameras */
1134 void DepsgraphNodeBuilder::build_camera(Object *object)
1135 {
1136         /* Object itself. */
1137         add_operation_node(&object->id,
1138                            DEG_NODE_TYPE_PARAMETERS,
1139                            NULL,
1140                            DEG_OPCODE_PARAMETERS_EVAL,
1141                            "Camera Parameters");
1142
1143         /* Object data. */
1144         /* TODO: Link scene-camera links in somehow. */
1145         Camera *cam = (Camera *)object->data;
1146         ID *camera_id = &cam->id;
1147         if (camera_id->tag & LIB_TAG_DOIT) {
1148                 return;
1149         }
1150
1151         build_animdata(&cam->id);
1152
1153         add_operation_node(camera_id,
1154                            DEG_NODE_TYPE_PARAMETERS,
1155                            NULL,
1156                            DEG_OPCODE_PARAMETERS_EVAL);
1157 }
1158
1159 /* Lamps */
1160 void DepsgraphNodeBuilder::build_lamp(Object *object)
1161 {
1162         /* Object itself. */
1163         add_operation_node(&object->id,
1164                            DEG_NODE_TYPE_PARAMETERS,
1165                            NULL,
1166                            DEG_OPCODE_PARAMETERS_EVAL,
1167                            "Lamp Parameters");
1168
1169         /* Object data. */
1170         Lamp *la = (Lamp *)object->data;
1171         ID *lamp_id = &la->id;
1172         if (lamp_id->tag & LIB_TAG_DOIT) {
1173                 return;
1174         }
1175
1176         build_animdata(&la->id);
1177
1178         add_operation_node(lamp_id,
1179                            DEG_NODE_TYPE_PARAMETERS,
1180                            NULL,
1181                            DEG_OPCODE_PARAMETERS_EVAL);
1182
1183         /* lamp's nodetree */
1184         if (la->nodetree) {
1185                 build_nodetree(la->nodetree);
1186         }
1187
1188         /* textures */
1189         build_texture_stack(la->mtex);
1190 }
1191
1192 void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
1193 {
1194         if (ntree == NULL) {
1195                 return;
1196         }
1197         /* nodetree itself */
1198         ID *ntree_id = &ntree->id;
1199         add_id_node(ntree_id);
1200         bNodeTree *ntree_cow = get_cow_datablock(ntree);
1201         /* Animation, */
1202         build_animdata(ntree_id);
1203         /* Shading update. */
1204         add_operation_node(ntree_id,
1205                            DEG_NODE_TYPE_SHADING,
1206                            NULL,
1207                            DEG_OPCODE_MATERIAL_UPDATE);
1208         /* NOTE: We really pass original and CoW node trees here, this is how the
1209          * callback works. Ideally we need to find a better way for that.
1210          */
1211         add_operation_node(ntree_id,
1212                            DEG_NODE_TYPE_SHADING_PARAMETERS,
1213                            function_bind(BKE_nodetree_shading_params_eval,
1214                                          _1,
1215                                          ntree_cow,
1216                                          ntree),
1217                            DEG_OPCODE_MATERIAL_UPDATE);
1218         /* nodetree's nodes... */
1219         LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) {
1220                 ID *id = bnode->id;
1221                 if (id == NULL) {
1222                         continue;
1223                 }
1224                 ID_Type id_type = GS(id->name);
1225                 if (id_type == ID_MA) {
1226                         build_material((Material *)id);
1227                 }
1228                 else if (id_type == ID_TE) {
1229                         build_texture((Tex *)id);
1230                 }
1231                 else if (id_type == ID_IM) {
1232                         build_image((Image *)id);
1233                 }
1234                 else if (id_type == ID_OB) {
1235                         build_object(NULL, (Object *)id, DEG_ID_LINKED_INDIRECTLY);
1236                 }
1237                 else if (id_type == ID_SCE) {
1238                         /* Scenes are used by compositor trees, and handled by render
1239                          * pipeline. No need to build dependencies for them here.
1240                          */
1241                 }
1242                 else if (bnode->type == NODE_GROUP) {
1243                         bNodeTree *group_ntree = (bNodeTree *)id;
1244                         if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) {
1245                                 build_nodetree(group_ntree);
1246                         }
1247                 }
1248                 else {
1249                         BLI_assert(!"Unknown ID type used for node");
1250                 }
1251         }
1252
1253         // TODO: link from nodetree to owner_component?
1254 }
1255
1256 /* Recursively build graph for material */
1257 void DepsgraphNodeBuilder::build_material(Material *material)
1258 {
1259         ID *material_id = &material->id;
1260         if (material_id->tag & LIB_TAG_DOIT) {
1261                 return;
1262         }
1263         material_id->tag |= LIB_TAG_DOIT;
1264         /* Material itself. */
1265         add_id_node(material_id);
1266         Material *material_cow = get_cow_datablock(material);
1267         /* Shading update. */
1268         add_operation_node(material_id,
1269                            DEG_NODE_TYPE_SHADING,
1270                            function_bind(BKE_material_eval,
1271                                          _1,
1272                                          material_cow),
1273                            DEG_OPCODE_MATERIAL_UPDATE);
1274         /* Material animation. */
1275         build_animdata(material_id);
1276         /* Textures. */
1277         build_texture_stack(material->mtex);
1278         /* Material's nodetree. */
1279         build_nodetree(material->nodetree);
1280 }
1281
1282 /* Texture-stack attached to some shading datablock */
1283 void DepsgraphNodeBuilder::build_texture_stack(MTex **texture_stack)
1284 {
1285         /* for now assume that all texture-stacks have same number of max items */
1286         for (int i = 0; i < MAX_MTEX; i++) {
1287                 MTex *mtex = texture_stack[i];
1288                 if (mtex && mtex->tex) {
1289                         build_texture(mtex->tex);
1290                 }
1291         }
1292 }
1293
1294 /* Recursively build graph for texture */
1295 void DepsgraphNodeBuilder::build_texture(Tex *tex)
1296 {
1297         ID *tex_id = &tex->id;
1298         if (tex_id->tag & LIB_TAG_DOIT) {
1299                 return;
1300         }
1301         tex_id->tag |= LIB_TAG_DOIT;
1302         /* Texture itself. */
1303         build_animdata(tex_id);
1304         /* Texture's nodetree. */
1305         build_nodetree(tex->nodetree);
1306         /* Special cases for different IDs which texture uses. */
1307         if (tex->type == TEX_IMAGE) {
1308                 if (tex->ima != NULL) {
1309                         build_image(tex->ima);
1310                 }
1311         }
1312 }
1313
1314 void DepsgraphNodeBuilder::build_image(Image *image) {
1315         ID *image_id = &image->id;
1316         if (image_id->tag & LIB_TAG_DOIT) {
1317                 return;
1318         }
1319         image_id->tag |= LIB_TAG_DOIT;
1320         /* Placeholder so we can add relations and tag ID node for update. */
1321         add_operation_node(image_id,
1322                            DEG_NODE_TYPE_PARAMETERS,
1323                            NULL,
1324                            DEG_OPCODE_PLACEHOLDER,
1325                            "Image Eval");
1326 }
1327
1328 void DepsgraphNodeBuilder::build_compositor(Scene *scene)
1329 {
1330         /* For now, just a plain wrapper? */
1331         // TODO: create compositing component?
1332         // XXX: component type undefined!
1333         //graph->get_node(&scene->id, NULL, DEG_NODE_TYPE_COMPOSITING, NULL);
1334
1335         /* for now, nodetrees are just parameters; compositing occurs in internals
1336          * of renderer...
1337          */
1338         add_component_node(&scene->id, DEG_NODE_TYPE_PARAMETERS);
1339         build_nodetree(scene->nodetree);
1340 }
1341
1342 void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd)
1343 {
1344         ID *gpd_id = &gpd->id;
1345
1346         /* TODO(sergey): what about multiple users of same datablock? This should
1347          * only get added once.
1348          */
1349
1350         /* The main reason Grease Pencil is included here is because the animation
1351          * (and drivers) need to be hosted somewhere.
1352          */
1353         build_animdata(gpd_id);
1354 }
1355
1356 void DepsgraphNodeBuilder::build_cachefile(CacheFile *cache_file)
1357 {
1358         ID *cache_file_id = &cache_file->id;
1359         /* Animation, */
1360         build_animdata(cache_file_id);
1361         /* Cache evaluation itself. */
1362         add_operation_node(cache_file_id, DEG_NODE_TYPE_CACHE, NULL,
1363                            DEG_OPCODE_PLACEHOLDER, "Cache File Update");
1364 }
1365
1366 void DepsgraphNodeBuilder::build_mask(Mask *mask)
1367 {
1368         ID *mask_id = &mask->id;
1369         Mask *mask_cow = get_cow_datablock(mask);
1370         /* F-Curve based animation. */
1371         build_animdata(mask_id);
1372         /* Animation based on mask's shapes. */
1373         add_operation_node(mask_id,
1374                            DEG_NODE_TYPE_ANIMATION,
1375                            function_bind(BKE_mask_eval_animation, _1, mask_cow),
1376                            DEG_OPCODE_MASK_ANIMATION);
1377         /* Final mask evaluation. */
1378         add_operation_node(mask_id,
1379                            DEG_NODE_TYPE_PARAMETERS,
1380                            function_bind(BKE_mask_eval_update, _1, mask_cow),
1381                            DEG_OPCODE_MASK_EVAL);
1382 }
1383
1384 void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip)
1385 {
1386         ID *clip_id = &clip->id;
1387         MovieClip *clip_cow = get_cow_datablock(clip);
1388         /* Animation. */
1389         build_animdata(clip_id);
1390         /* Movie clip evaluation. */
1391         add_operation_node(clip_id,
1392                            DEG_NODE_TYPE_PARAMETERS,
1393                            function_bind(BKE_movieclip_eval_update, _1, clip_cow),
1394                            DEG_OPCODE_MOVIECLIP_EVAL);
1395 }
1396
1397 void DepsgraphNodeBuilder::build_lightprobe(Object *object)
1398 {
1399         LightProbe *probe = (LightProbe *)object->data;
1400         ID *probe_id = &probe->id;
1401         if (probe_id->tag & LIB_TAG_DOIT) {
1402                 return;
1403         }
1404         probe_id->tag |= LIB_TAG_DOIT;
1405         /* Placeholder so we can add relations and tag ID node for update. */
1406         add_operation_node(probe_id,
1407                            DEG_NODE_TYPE_PARAMETERS,
1408                            NULL,
1409                            DEG_OPCODE_PLACEHOLDER,
1410                            "LightProbe Eval");
1411         add_operation_node(&object->id,
1412                            DEG_NODE_TYPE_PARAMETERS,
1413                            NULL,
1414                            DEG_OPCODE_PLACEHOLDER,
1415                            "LightProbe Eval");
1416
1417         build_animdata(probe_id);
1418 }
1419
1420 }  // namespace DEG