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