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