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