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