3753606862e330449c2bcefe5eeda6ac43b11db0
[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_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_lightprobe(Object *object)
592 {
593         LightProbe *probe = (LightProbe *)object->data;
594         build_lightprobe(probe);
595         add_operation_node(&object->id,
596                            DEG_NODE_TYPE_PARAMETERS,
597                            NULL,
598                            DEG_OPCODE_LIGHT_PROBE_EVAL);
599 }
600
601 void DepsgraphNodeBuilder::build_object_transform(Object *object)
602 {
603         OperationDepsNode *op_node;
604         Scene *scene_cow = get_cow_datablock(scene_);
605         Object *ob_cow = get_cow_datablock(object);
606
607         /* local transforms (from transform channels - loc/rot/scale + deltas) */
608         op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
609                                      function_bind(BKE_object_eval_local_transform,
610                                                    _1,
611                                                    ob_cow),
612                                      DEG_OPCODE_TRANSFORM_LOCAL);
613         op_node->set_as_entry();
614
615         /* object parent */
616         if (object->parent != NULL) {
617                 add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
618                                    function_bind(BKE_object_eval_parent,
619                                                  _1,
620                                                  scene_cow,
621                                                  ob_cow),
622                                    DEG_OPCODE_TRANSFORM_PARENT);
623         }
624
625         /* object constraints */
626         if (object->constraints.first != NULL) {
627                 build_object_constraints(object);
628         }
629
630         /* Rest of transformation update. */
631         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
632                            function_bind(BKE_object_eval_uber_transform,
633                                          _1,
634                                          ob_cow),
635                            DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
636
637         /* object transform is done */
638         op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
639                                      function_bind(BKE_object_eval_done,
640                                                    _1,
641                                                    ob_cow),
642                                      DEG_OPCODE_TRANSFORM_FINAL);
643         op_node->set_as_exit();
644 }
645
646 /**
647  * Constraints Graph Notes
648  *
649  * For constraints, we currently only add a operation node to the Transform
650  * or Bone components (depending on whichever type of owner we have).
651  * This represents the entire constraints stack, which is for now just
652  * executed as a single monolithic block. At least initially, this should
653  * be sufficient for ensuring that the porting/refactoring process remains
654  * manageable.
655  *
656  * However, when the time comes for developing "node-based" constraints,
657  * we'll need to split this up into pre/post nodes for "constraint stack
658  * evaluation" + operation nodes for each constraint (i.e. the contents
659  * of the loop body used in the current "solve_constraints()" operation).
660  *
661  * -- Aligorith, August 2013
662  */
663 void DepsgraphNodeBuilder::build_object_constraints(Object *object)
664 {
665         /* create node for constraint stack */
666         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
667                            function_bind(BKE_object_eval_constraints,
668                                          _1,
669                                          get_cow_datablock(scene_),
670                                          get_cow_datablock(object)),
671                            DEG_OPCODE_TRANSFORM_CONSTRAINTS);
672 }
673
674 /**
675  * Build graph nodes for AnimData block
676  * \param id: ID-Block which hosts the AnimData
677  */
678 void DepsgraphNodeBuilder::build_animdata(ID *id)
679 {
680         AnimData *adt = BKE_animdata_from_id(id);
681         if (adt == NULL) {
682                 return;
683         }
684         /* animation */
685         if (adt->action || adt->nla_tracks.first || adt->drivers.first) {
686                 (void) add_id_node(id);
687                 ID *id_cow = get_cow_id(id);
688
689                 if (adt->action != NULL &&
690                     !built_map_.checkIsBuiltAndTag(&adt->action->id))
691                 {
692                         add_operation_node(&adt->action->id, DEG_NODE_TYPE_ANIMATION,
693                                            NULL,
694                                            DEG_OPCODE_ANIMATION);
695                 }
696
697                 // XXX: Hook up specific update callbacks for special properties which
698                 // may need it...
699
700                 /* actions and NLA - as a single unit for now, as it gets complicated to
701                  * schedule otherwise.
702                  */
703                 if ((adt->action) || (adt->nla_tracks.first)) {
704                         /* create the node */
705                         add_operation_node(id, DEG_NODE_TYPE_ANIMATION,
706                                            function_bind(BKE_animsys_eval_animdata,
707                                                          _1,
708                                                          id_cow),
709                                            DEG_OPCODE_ANIMATION,
710                                            id->name);
711
712                         /* TODO: for each channel affected, we might also want to add some
713                          * support for running RNA update callbacks on them
714                          * (which will be needed for proper handling of drivers later)
715                          */
716                 }
717
718                 /* drivers */
719                 int driver_index = 0;
720                 LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
721                         /* create driver */
722                         build_driver(id, fcu, driver_index++);
723                 }
724         }
725 }
726
727 /**
728  * Build graph node(s) for Driver
729  * \param id: ID-Block that driver is attached to
730  * \param fcu: Driver-FCurve
731  * \param driver_index: Index in animation data drivers list
732  */
733 void DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcurve, int driver_index)
734 {
735         /* Create data node for this driver */
736         ID *id_cow = get_cow_id(id);
737         ChannelDriver *driver_orig = fcurve->driver;
738
739         /* TODO(sergey): ideally we could pass the COW of fcu, but since it
740          * has not yet been allocated at this point we can't. As a workaround
741          * the animation systems allocates an array so we can do a fast lookup
742          * with the driver index. */
743         ensure_operation_node(id,
744                               DEG_NODE_TYPE_PARAMETERS,
745                               function_bind(BKE_animsys_eval_driver, _1, id_cow, driver_index, driver_orig),
746                               DEG_OPCODE_DRIVER,
747                               fcurve->rna_path ? fcurve->rna_path : "",
748                               fcurve->array_index);
749         build_driver_variables(id, fcurve);
750 }
751
752 void DepsgraphNodeBuilder::build_driver_variables(ID * id, FCurve *fcurve)
753 {
754         build_driver_id_property(id, fcurve->rna_path);
755         LISTBASE_FOREACH (DriverVar *, dvar, &fcurve->driver->variables) {
756                 DRIVER_TARGETS_USED_LOOPER(dvar)
757                 {
758                         build_id(dtar->id);
759                         build_driver_id_property(dtar->id, dtar->rna_path);
760                 }
761                 DRIVER_TARGETS_LOOPER_END
762         }
763 }
764
765 void DepsgraphNodeBuilder::build_driver_id_property(ID *id,
766                                                     const char *rna_path)
767 {
768         if (id == NULL || rna_path == NULL) {
769                 return;
770         }
771         PointerRNA id_ptr, ptr;
772         PropertyRNA *prop;
773         RNA_id_pointer_create(id, &id_ptr);
774         if (!RNA_path_resolve_full(&id_ptr, rna_path, &ptr, &prop, NULL)) {
775                 return;
776         }
777         if (prop == NULL) {
778                 return;
779         }
780         if (!RNA_property_is_idprop(prop)) {
781                 return;
782         }
783         const char *prop_identifier = RNA_property_identifier((PropertyRNA *)prop);
784         ensure_operation_node(id,
785                               DEG_NODE_TYPE_PARAMETERS,
786                               NULL,
787                               DEG_OPCODE_ID_PROPERTY,
788                               prop_identifier);
789 }
790
791 /* Recursively build graph for world */
792 void DepsgraphNodeBuilder::build_world(World *world)
793 {
794         if (built_map_.checkIsBuiltAndTag(world)) {
795                 return;
796         }
797         /* Animation. */
798         build_animdata(&world->id);
799         /* world itself */
800         add_operation_node(&world->id,
801                            DEG_NODE_TYPE_SHADING,
802                            function_bind(BKE_world_eval,
803                                          _1,
804                                          get_cow_datablock(world)),
805                            DEG_OPCODE_WORLD_UPDATE);
806         /* world's nodetree */
807         if (world->nodetree != NULL) {
808                 build_nodetree(world->nodetree);
809         }
810 }
811
812 /* Rigidbody Simulation - Scene Level */
813 void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
814 {
815         RigidBodyWorld *rbw = scene->rigidbody_world;
816         Scene *scene_cow = get_cow_datablock(scene);
817
818         /**
819          * Rigidbody Simulation Nodes
820          * ==========================
821          *
822          * There are 3 nodes related to Rigidbody Simulation:
823          * 1) "Initialize/Rebuild World" - this is called sparingly, only when the
824          *    simulation needs to be rebuilt (mainly after file reload, or moving
825          *    back to start frame)
826          * 2) "Do Simulation" - perform a simulation step - interleaved between the
827          *    evaluation steps for clusters of objects (i.e. between those affected
828          *    and/or not affected by the sim for instance).
829          *
830          * 3) "Pull Results" - grab the specific transforms applied for a specific
831          *    object - performed as part of object's transform-stack building.
832          */
833
834         /* Create nodes --------------------------------------------------------- */
835
836         /* XXX: is this the right component, or do we want to use another one
837          * instead?
838          */
839
840         /* init/rebuild operation */
841         /*OperationDepsNode *init_node =*/ add_operation_node(
842                 &scene->id, DEG_NODE_TYPE_TRANSFORM,
843                 function_bind(BKE_rigidbody_rebuild_sim, _1, scene_cow),
844                 DEG_OPCODE_RIGIDBODY_REBUILD);
845
846         /* do-sim operation */
847         // XXX: what happens if we need to split into several groups?
848         OperationDepsNode *sim_node = add_operation_node(
849                 &scene->id, DEG_NODE_TYPE_TRANSFORM,
850                 function_bind(BKE_rigidbody_eval_simulation, _1, scene_cow),
851                 DEG_OPCODE_RIGIDBODY_SIM);
852
853         /* XXX: For now, the sim node is the only one that really matters here.
854          * If any other sims get added later, we may have to remove these hacks...
855          */
856         sim_node->owner->entry_operation = sim_node;
857         sim_node->owner->exit_operation  = sim_node;
858
859         /* objects - simulation participants */
860         if (rbw->group) {
861                 const ListBase group_objects = BKE_collection_object_cache_get(rbw->group);
862                 LISTBASE_FOREACH (Base *, base, &group_objects) {
863                         Object *object = base->object;
864
865                         if (!object || (object->type != OB_MESH))
866                                 continue;
867
868                         /* 2) create operation for flushing results */
869                         /* object's transform component - where the rigidbody operation
870                          * lives. */
871                         add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
872                                            function_bind(
873                                                    BKE_rigidbody_object_sync_transforms,
874                                                    _1,
875                                                    scene_cow,
876                                                    get_cow_datablock(object)),
877                                            DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
878                 }
879         }
880 }
881
882 void DepsgraphNodeBuilder::build_particles(Object *object)
883 {
884         /**
885          * Particle Systems Nodes
886          * ======================
887          *
888          * There are two types of nodes associated with representing
889          * particle systems:
890          *  1) Component (EVAL_PARTICLES) - This is the particle-system
891          *     evaluation context for an object. It acts as the container
892          *     for all the nodes associated with a particular set of particle
893          *     systems.
894          *  2) Particle System Eval Operation - This operation node acts as a
895          *     blackbox evaluation step for one particle system referenced by
896          *     the particle systems stack. All dependencies link to this operation.
897          */
898         /* Component for all particle systems. */
899         ComponentDepsNode *psys_comp =
900                 add_component_node(&object->id, DEG_NODE_TYPE_EVAL_PARTICLES);
901
902         /* TODO(sergey): Need to get COW of PSYS. */
903         Scene *scene_cow = get_cow_datablock(scene_);
904         Object *ob_cow = get_cow_datablock(object);
905
906         add_operation_node(psys_comp,
907                            function_bind(BKE_particle_system_eval_init,
908                                          _1,
909                                          scene_cow,
910                                          ob_cow),
911                            DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
912         /* Build all particle systems. */
913         LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
914                 ParticleSettings *part = psys->part;
915                 /* Build particle settings operations.
916                  *
917                  * NOTE: The call itself ensures settings are only build once.
918                  */
919                 build_particle_settings(part);
920                 /* Particle system evaluation. */
921                 add_operation_node(psys_comp,
922                                    NULL,
923                                    DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
924                                    psys->name);
925                 /* Visualization of particle system. */
926                 switch (part->ren_as) {
927                         case PART_DRAW_OB:
928                                 if (part->dup_ob != NULL) {
929                                         build_object(-1,
930                                                      part->dup_ob,
931                                                      DEG_ID_LINKED_INDIRECTLY);
932                                 }
933                                 break;
934                         case PART_DRAW_GR:
935                                 if (part->dup_group != NULL) {
936                                         build_collection(part->dup_group);
937                                 }
938                                 break;
939                 }
940         }
941
942         /* TODO(sergey): Do we need a point cache operations here? */
943         add_operation_node(&object->id,
944                            DEG_NODE_TYPE_CACHE,
945                            function_bind(BKE_ptcache_object_reset,
946                                          scene_cow,
947                                          ob_cow,
948                                          PTCACHE_RESET_DEPSGRAPH),
949                            DEG_OPCODE_POINT_CACHE_RESET);
950 }
951
952 void DepsgraphNodeBuilder::build_particle_settings(ParticleSettings *part) {
953         if (built_map_.checkIsBuiltAndTag(part)) {
954                 return;
955         }
956         /* Animation data. */
957         build_animdata(&part->id);
958         /* Parameters change. */
959         add_operation_node(&part->id,
960                            DEG_NODE_TYPE_PARAMETERS,
961                            NULL,
962                            DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
963 }
964
965 void DepsgraphNodeBuilder::build_cloth(Object *object)
966 {
967         Scene *scene_cow = get_cow_datablock(scene_);
968         Object *object_cow = get_cow_datablock(object);
969         add_operation_node(&object->id,
970                            DEG_NODE_TYPE_CACHE,
971                            function_bind(BKE_object_eval_cloth,
972                                          _1,
973                                          scene_cow,
974                                          object_cow),
975                            DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER);
976 }
977
978 /* Shapekeys */
979 void DepsgraphNodeBuilder::build_shapekeys(Key *key)
980 {
981         build_animdata(&key->id);
982         add_operation_node(&key->id,
983                            DEG_NODE_TYPE_GEOMETRY,
984                            NULL,
985                            DEG_OPCODE_GEOMETRY_SHAPEKEY);
986 }
987
988 /* ObData Geometry Evaluation */
989 // XXX: what happens if the datablock is shared!
990 void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
991 {
992         OperationDepsNode *op_node;
993         Scene *scene_cow = get_cow_datablock(scene_);
994         Object *object_cow = get_cow_datablock(object);
995
996         /* Temporary uber-update node, which does everything.
997          * It is for the being we're porting old dependencies into the new system.
998          * We'll get rid of this node as soon as all the granular update functions
999          * are filled in.
1000          *
1001          * TODO(sergey): Get rid of this node.
1002          */
1003         op_node = add_operation_node(&object->id,
1004                                      DEG_NODE_TYPE_GEOMETRY,
1005                                      function_bind(BKE_object_eval_uber_data,
1006                                                    _1,
1007                                                    scene_cow,
1008                                                    object_cow),
1009                                      DEG_OPCODE_GEOMETRY_UBEREVAL);
1010         op_node->set_as_exit();
1011
1012         op_node = add_operation_node(&object->id,
1013                                      DEG_NODE_TYPE_GEOMETRY,
1014                                      NULL,
1015                                      DEG_OPCODE_PLACEHOLDER,
1016                                      "Eval Init");
1017         op_node->set_as_entry();
1018
1019         // TODO: "Done" operation
1020
1021         /* Cloth modifier. */
1022         LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
1023                 if (md->type == eModifierType_Cloth) {
1024                         build_cloth(object);
1025                 }
1026         }
1027
1028         /* materials */
1029         if (object->totcol != 0) {
1030                 if (object->type == OB_MESH) {
1031                         add_operation_node(&object->id,
1032                                            DEG_NODE_TYPE_SHADING,
1033                                            function_bind(BKE_object_eval_update_shading,
1034                                                          _1,
1035                                                          object_cow),
1036                                            DEG_OPCODE_SHADING);
1037                 }
1038
1039                 for (int a = 1; a <= object->totcol; a++) {
1040                         Material *ma = give_current_material(object, a);
1041                         if (ma != NULL) {
1042                                 build_material(ma);
1043                         }
1044                 }
1045         }
1046
1047         /* geometry collision */
1048         if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1049                 // add geometry collider relations
1050         }
1051
1052         ID *obdata = (ID *)object->data;
1053         if (built_map_.checkIsBuiltAndTag(obdata)) {
1054                 return;
1055         }
1056         /* Make sure we've got an ID node before requesting CoW pointer. */
1057         (void) add_id_node((ID *)obdata);
1058         ID *obdata_cow = get_cow_id(obdata);
1059
1060         /* ShapeKeys */
1061         Key *key = BKE_key_from_object(object);
1062         if (key) {
1063                 build_shapekeys(key);
1064         }
1065
1066         build_animdata(obdata);
1067
1068         /* Nodes for result of obdata's evaluation, and geometry
1069          * evaluation on object.
1070          */
1071         switch (object->type) {
1072                 case OB_MESH:
1073                 {
1074                         //Mesh *me = (Mesh *)object->data;
1075
1076                         /* evaluation operations */
1077                         op_node = add_operation_node(obdata,
1078                                                      DEG_NODE_TYPE_GEOMETRY,
1079                                                      function_bind(BKE_mesh_eval_geometry,
1080                                                                    _1,
1081                                                                    (Mesh *)obdata_cow),
1082                                                      DEG_OPCODE_PLACEHOLDER,
1083                                                      "Geometry Eval");
1084                         op_node->set_as_entry();
1085                         break;
1086                 }
1087
1088                 case OB_MBALL:
1089                 {
1090                         op_node = add_operation_node(obdata,
1091                                                      DEG_NODE_TYPE_GEOMETRY,
1092                                                      NULL,
1093                                                      DEG_OPCODE_PLACEHOLDER,
1094                                                      "Geometry Eval");
1095                         op_node->set_as_entry();
1096                         break;
1097                 }
1098
1099                 case OB_CURVE:
1100                 case OB_SURF:
1101                 case OB_FONT:
1102                 {
1103                         /* Curve/nurms evaluation operations. */
1104                         /* - calculate curve geometry (including path) */
1105                         op_node = add_operation_node(obdata,
1106                                                      DEG_NODE_TYPE_GEOMETRY,
1107                                                      function_bind(BKE_curve_eval_geometry,
1108                                                                    _1,
1109                                                                    (Curve *)obdata_cow),
1110                                                                    DEG_OPCODE_PLACEHOLDER,
1111                                                                    "Geometry Eval");
1112                         op_node->set_as_entry();
1113                         /* Make sure objects used for bevel.taper are in the graph.
1114                          * NOTE: This objects might be not linked to the scene.
1115                          */
1116                         Curve *cu = (Curve *)obdata;
1117                         if (cu->bevobj != NULL) {
1118                                 build_object(-1, cu->bevobj, DEG_ID_LINKED_INDIRECTLY);
1119                         }
1120                         if (cu->taperobj != NULL) {
1121                                 build_object(-1, cu->taperobj, DEG_ID_LINKED_INDIRECTLY);
1122                         }
1123                         if (object->type == OB_FONT && cu->textoncurve != NULL) {
1124                                 build_object(-1, cu->textoncurve, DEG_ID_LINKED_INDIRECTLY);
1125                         }
1126                         break;
1127                 }
1128
1129                 case OB_LATTICE:
1130                 {
1131                         /* Lattice evaluation operations. */
1132                         op_node = add_operation_node(obdata,
1133                                                      DEG_NODE_TYPE_GEOMETRY,
1134                                                      function_bind(BKE_lattice_eval_geometry,
1135                                                                    _1,
1136                                                                    (Lattice *)obdata_cow),
1137                                                                    DEG_OPCODE_PLACEHOLDER,
1138                                                                    "Geometry Eval");
1139                         op_node->set_as_entry();
1140                         break;
1141                 }
1142         }
1143
1144         op_node = add_operation_node(obdata, DEG_NODE_TYPE_GEOMETRY, NULL,
1145                                      DEG_OPCODE_PLACEHOLDER, "Eval Done");
1146         op_node->set_as_exit();
1147
1148         /* Parameters for driver sources. */
1149         add_operation_node(obdata,
1150                            DEG_NODE_TYPE_PARAMETERS,
1151                            NULL,
1152                            DEG_OPCODE_PARAMETERS_EVAL);
1153
1154         /* Batch cache. */
1155         add_operation_node(obdata,
1156                            DEG_NODE_TYPE_BATCH_CACHE,
1157                            function_bind(BKE_object_data_select_update,
1158                                          _1,
1159                                          obdata_cow),
1160                            DEG_OPCODE_GEOMETRY_SELECT_UPDATE);
1161 }
1162
1163 /* Cameras */
1164 void DepsgraphNodeBuilder::build_camera(Object *object)
1165 {
1166         /* Object data. */
1167         /* TODO: Link scene-camera links in somehow... */
1168         Camera *camera = (Camera *)object->data;
1169         if (built_map_.checkIsBuiltAndTag(camera)) {
1170                 return;
1171         }
1172         build_animdata(&camera->id);
1173         add_operation_node(&camera->id,
1174                            DEG_NODE_TYPE_PARAMETERS,
1175                            NULL,
1176                            DEG_OPCODE_PARAMETERS_EVAL);
1177 }
1178
1179 /* Lamps */
1180 void DepsgraphNodeBuilder::build_lamp(Object *object)
1181 {
1182         /* Object data. */
1183         Lamp *lamp = (Lamp *)object->data;
1184         if (built_map_.checkIsBuiltAndTag(lamp)) {
1185                 return;
1186         }
1187         build_animdata(&lamp->id);
1188         add_operation_node(&lamp->id,
1189                            DEG_NODE_TYPE_PARAMETERS,
1190                            NULL,
1191                            DEG_OPCODE_PARAMETERS_EVAL);
1192         /* lamp's nodetree */
1193         build_nodetree(lamp->nodetree);
1194 }
1195
1196 void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
1197 {
1198         if (ntree == NULL) {
1199                 return;
1200         }
1201         if (built_map_.checkIsBuiltAndTag(ntree)) {
1202                 return;
1203         }
1204         /* nodetree itself */
1205         add_id_node(&ntree->id);
1206         bNodeTree *ntree_cow = get_cow_datablock(ntree);
1207         /* Animation, */
1208         build_animdata(&ntree->id);
1209         /* Shading update. */
1210         add_operation_node(&ntree->id,
1211                            DEG_NODE_TYPE_SHADING,
1212                            NULL,
1213                            DEG_OPCODE_MATERIAL_UPDATE);
1214         /* NOTE: We really pass original and CoW node trees here, this is how the
1215          * callback works. Ideally we need to find a better way for that.
1216          */
1217         add_operation_node(&ntree->id,
1218                            DEG_NODE_TYPE_SHADING_PARAMETERS,
1219                            function_bind(BKE_nodetree_shading_params_eval,
1220                                          _1,
1221                                          ntree_cow,
1222                                          ntree),
1223                            DEG_OPCODE_MATERIAL_UPDATE);
1224         /* nodetree's nodes... */
1225         LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) {
1226                 ID *id = bnode->id;
1227                 if (id == NULL) {
1228                         continue;
1229                 }
1230                 ID_Type id_type = GS(id->name);
1231                 if (id_type == ID_MA) {
1232                         build_material((Material *)id);
1233                 }
1234                 else if (id_type == ID_TE) {
1235                         build_texture((Tex *)id);
1236                 }
1237                 else if (id_type == ID_IM) {
1238                         build_image((Image *)id);
1239                 }
1240                 else if (id_type == ID_OB) {
1241                         build_object(-1, (Object *)id, DEG_ID_LINKED_INDIRECTLY);
1242                 }
1243                 else if (id_type == ID_SCE) {
1244                         /* Scenes are used by compositor trees, and handled by render
1245                          * pipeline. No need to build dependencies for them here.
1246                          */
1247                 }
1248                 else if (id_type == ID_TXT) {
1249                         /* Ignore script nodes. */
1250                 }
1251                 else if (bnode->type == NODE_GROUP) {
1252                         bNodeTree *group_ntree = (bNodeTree *)id;
1253                         build_nodetree(group_ntree);
1254                 }
1255                 else {
1256                         BLI_assert(!"Unknown ID type used for node");
1257                 }
1258         }
1259
1260         // TODO: link from nodetree to owner_component?
1261 }
1262
1263 /* Recursively build graph for material */
1264 void DepsgraphNodeBuilder::build_material(Material *material)
1265 {
1266         if (built_map_.checkIsBuiltAndTag(material)) {
1267                 return;
1268         }
1269         /* Material itself. */
1270         add_id_node(&material->id);
1271         Material *material_cow = get_cow_datablock(material);
1272         /* Shading update. */
1273         add_operation_node(&material->id,
1274                            DEG_NODE_TYPE_SHADING,
1275                            function_bind(BKE_material_eval,
1276                                          _1,
1277                                          material_cow),
1278                            DEG_OPCODE_MATERIAL_UPDATE);
1279         /* Material animation. */
1280         build_animdata(&material->id);
1281         /* Material's nodetree. */
1282         build_nodetree(material->nodetree);
1283 }
1284
1285 /* Recursively build graph for texture */
1286 void DepsgraphNodeBuilder::build_texture(Tex *texture)
1287 {
1288         if (built_map_.checkIsBuiltAndTag(texture)) {
1289                 return;
1290         }
1291         /* Texture itself. */
1292         build_animdata(&texture->id);
1293         /* Texture's nodetree. */
1294         build_nodetree(texture->nodetree);
1295         /* Special cases for different IDs which texture uses. */
1296         if (texture->type == TEX_IMAGE) {
1297                 if (texture->ima != NULL) {
1298                         build_image(texture->ima);
1299                 }
1300         }
1301         /* Placeholder so we can add relations and tag ID node for update. */
1302         add_operation_node(&texture->id,
1303                            DEG_NODE_TYPE_PARAMETERS,
1304                            NULL,
1305                            DEG_OPCODE_PLACEHOLDER);
1306 }
1307
1308 void DepsgraphNodeBuilder::build_image(Image *image) {
1309         if (built_map_.checkIsBuiltAndTag(image)) {
1310                 return;
1311         }
1312         /* Placeholder so we can add relations and tag ID node for update. */
1313         add_operation_node(&image->id,
1314                            DEG_NODE_TYPE_PARAMETERS,
1315                            NULL,
1316                            DEG_OPCODE_PLACEHOLDER,
1317                            "Image Eval");
1318 }
1319
1320 void DepsgraphNodeBuilder::build_compositor(Scene *scene)
1321 {
1322         /* For now, just a plain wrapper? */
1323         // TODO: create compositing component?
1324         // XXX: component type undefined!
1325         //graph->get_node(&scene->id, NULL, DEG_NODE_TYPE_COMPOSITING, NULL);
1326
1327         /* for now, nodetrees are just parameters; compositing occurs in internals
1328          * of renderer...
1329          */
1330         add_component_node(&scene->id, DEG_NODE_TYPE_PARAMETERS);
1331         build_nodetree(scene->nodetree);
1332 }
1333
1334 void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd)
1335 {
1336         if (built_map_.checkIsBuiltAndTag(gpd)) {
1337                 return;
1338         }
1339         ID *gpd_id = &gpd->id;
1340
1341         /* TODO(sergey): what about multiple users of same datablock? This should
1342          * only get added once.
1343          */
1344
1345         /* The main reason Grease Pencil is included here is because the animation
1346          * (and drivers) need to be hosted somewhere.
1347          */
1348         build_animdata(gpd_id);
1349 }
1350
1351 void DepsgraphNodeBuilder::build_cachefile(CacheFile *cache_file)
1352 {
1353         if (built_map_.checkIsBuiltAndTag(cache_file)) {
1354                 return;
1355         }
1356         ID *cache_file_id = &cache_file->id;
1357         /* Animation, */
1358         build_animdata(cache_file_id);
1359         /* Cache evaluation itself. */
1360         add_operation_node(cache_file_id, DEG_NODE_TYPE_CACHE, NULL,
1361                            DEG_OPCODE_PLACEHOLDER, "Cache File Update");
1362 }
1363
1364 void DepsgraphNodeBuilder::build_mask(Mask *mask)
1365 {
1366         if (built_map_.checkIsBuiltAndTag(mask)) {
1367                 return;
1368         }
1369         ID *mask_id = &mask->id;
1370         Mask *mask_cow = get_cow_datablock(mask);
1371         /* F-Curve based animation. */
1372         build_animdata(mask_id);
1373         /* Animation based on mask's shapes. */
1374         add_operation_node(mask_id,
1375                            DEG_NODE_TYPE_ANIMATION,
1376                            function_bind(BKE_mask_eval_animation, _1, mask_cow),
1377                            DEG_OPCODE_MASK_ANIMATION);
1378         /* Final mask evaluation. */
1379         add_operation_node(mask_id,
1380                            DEG_NODE_TYPE_PARAMETERS,
1381                            function_bind(BKE_mask_eval_update, _1, mask_cow),
1382                            DEG_OPCODE_MASK_EVAL);
1383 }
1384
1385 void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip)
1386 {
1387         if (built_map_.checkIsBuiltAndTag(clip)) {
1388                 return;
1389         }
1390         ID *clip_id = &clip->id;
1391         MovieClip *clip_cow = get_cow_datablock(clip);
1392         /* Animation. */
1393         build_animdata(clip_id);
1394         /* Movie clip evaluation. */
1395         add_operation_node(clip_id,
1396                            DEG_NODE_TYPE_PARAMETERS,
1397                            function_bind(BKE_movieclip_eval_update, _1, clip_cow),
1398                            DEG_OPCODE_MOVIECLIP_EVAL);
1399 }
1400
1401 void DepsgraphNodeBuilder::build_lightprobe(LightProbe *probe)
1402 {
1403         if (built_map_.checkIsBuiltAndTag(probe)) {
1404                 return;
1405         }
1406         /* Placeholder so we can add relations and tag ID node for update. */
1407         add_operation_node(&probe->id,
1408                            DEG_NODE_TYPE_PARAMETERS,
1409                            NULL,
1410                            DEG_OPCODE_LIGHT_PROBE_EVAL);
1411
1412         build_animdata(&probe->id);
1413 }
1414
1415 /* **** ID traversal callbacks functions **** */
1416
1417 void DepsgraphNodeBuilder::modifier_walk(void *user_data,
1418                                          struct Object * /*object*/,
1419                                          struct ID **idpoin,
1420                                          int /*cb_flag*/)
1421 {
1422         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
1423         ID *id = *idpoin;
1424         if (id == NULL) {
1425                 return;
1426         }
1427         switch (GS(id->name)) {
1428                 case ID_OB:
1429                         data->builder->build_object(-1,
1430                                                     (Object *)id,
1431                                                     DEG_ID_LINKED_INDIRECTLY);
1432                         break;
1433                 case ID_TE:
1434                         data->builder->build_texture((Tex *)id);
1435                         break;
1436                 default:
1437                         /* pass */
1438                         break;
1439         }
1440 }
1441
1442 void DepsgraphNodeBuilder::constraint_walk(bConstraint * /*con*/,
1443                                            ID **idpoin,
1444                                            bool /*is_reference*/,
1445                                            void *user_data)
1446 {
1447         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
1448         ID *id = *idpoin;
1449         if (id == NULL) {
1450                 return;
1451         }
1452         switch (GS(id->name)) {
1453                 case ID_OB:
1454                         data->builder->build_object(-1,
1455                                                     (Object *)id,
1456                                                     DEG_ID_LINKED_INDIRECTLY);
1457                         break;
1458                 default:
1459                         /* pass */
1460                         break;
1461         }
1462 }
1463
1464 }  // namespace DEG