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