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