bgl do not bind parts of OpenGL that are not exposed in core profiles
[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 extern "C" {
41 #include "BLI_blenlib.h"
42 #include "BLI_string.h"
43 #include "BLI_utildefines.h"
44
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_mesh_types.h"
59 #include "DNA_meta_types.h"
60 #include "DNA_node_types.h"
61 #include "DNA_object_types.h"
62 #include "DNA_rigidbody_types.h"
63 #include "DNA_scene_types.h"
64 #include "DNA_texture_types.h"
65 #include "DNA_world_types.h"
66
67 #include "BKE_action.h"
68 #include "BKE_armature.h"
69 #include "BKE_animsys.h"
70 #include "BKE_constraint.h"
71 #include "BKE_curve.h"
72 #include "BKE_depsgraph.h"
73 #include "BKE_effect.h"
74 #include "BKE_fcurve.h"
75 #include "BKE_idcode.h"
76 #include "BKE_group.h"
77 #include "BKE_key.h"
78 #include "BKE_lattice.h"
79 #include "BKE_library.h"
80 #include "BKE_main.h"
81 #include "BKE_material.h"
82 #include "BKE_mesh.h"
83 #include "BKE_mball.h"
84 #include "BKE_modifier.h"
85 #include "BKE_node.h"
86 #include "BKE_object.h"
87 #include "BKE_rigidbody.h"
88 #include "BKE_sound.h"
89 #include "BKE_texture.h"
90 #include "BKE_tracking.h"
91 #include "BKE_world.h"
92
93 #include "DEG_depsgraph.h"
94 #include "DEG_depsgraph_build.h"
95
96 #include "RNA_access.h"
97 #include "RNA_types.h"
98 } /* extern "C" */
99
100 #include "intern/builder/deg_builder.h"
101 #include "intern/nodes/deg_node.h"
102 #include "intern/nodes/deg_node_component.h"
103 #include "intern/nodes/deg_node_operation.h"
104 #include "intern/depsgraph_types.h"
105 #include "intern/depsgraph_intern.h"
106
107 namespace DEG {
108
109 namespace {
110
111 struct BuilderWalkUserData {
112         DepsgraphNodeBuilder *builder;
113         Scene *scene;
114 };
115
116 static void modifier_walk(void *user_data,
117                           struct Object * /*ob*/,
118                           struct Object **obpoin,
119                           int /*cd_flag*/)
120 {
121         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
122         if (*obpoin) {
123                 data->builder->build_object(data->scene, NULL, *obpoin);
124         }
125 }
126
127 void constraint_walk(bConstraint * /*con*/,
128                      ID **idpoin,
129                      bool /*is_reference*/,
130                      void *user_data)
131 {
132         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
133         if (*idpoin) {
134                 ID *id = *idpoin;
135                 if (GS(id->name) == ID_OB) {
136                         data->builder->build_object(data->scene, NULL, (Object *)id);
137                 }
138         }
139 }
140
141 }  /* namespace */
142
143 /* ************ */
144 /* Node Builder */
145
146 /* **** General purpose functions **** */
147
148 DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph) :
149     m_bmain(bmain),
150     m_graph(graph)
151 {
152 }
153
154 DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
155 {
156 }
157
158 RootDepsNode *DepsgraphNodeBuilder::add_root_node()
159 {
160         return m_graph->add_root_node();
161 }
162
163 IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id)
164 {
165         return m_graph->add_id_node(id, id->name);
166 }
167
168 TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source(ID *id)
169 {
170         /* determine which node to attach timesource to */
171         if (id) {
172 #if 0 /* XXX TODO */
173                 /* get ID node */
174                 IDDepsNode id_node = m_graph->find_id_node(id);
175
176                 /* depends on what this is... */
177                 switch (GS(id->name)) {
178                         case ID_SCE: /* Scene - Usually sequencer strip causing time remapping... */
179                         {
180                                 // TODO...
181                         }
182                         break;
183
184                         case ID_GR: /* Group */
185                         {
186                                 // TODO...
187                         }
188                         break;
189
190                         // XXX: time source...
191
192                         default:     /* Unhandled */
193                                 printf("%s(): Unhandled ID - %s \n", __func__, id->name);
194                                 break;
195                 }
196 #endif
197         }
198         else {
199                 /* root-node */
200                 RootDepsNode *root_node = m_graph->root_node;
201                 if (root_node) {
202                         return root_node->add_time_source("Time Source");
203                 }
204         }
205
206         return NULL;
207 }
208
209 ComponentDepsNode *DepsgraphNodeBuilder::add_component_node(
210         ID *id,
211         eDepsNode_Type comp_type,
212         const char *comp_name)
213 {
214         IDDepsNode *id_node = add_id_node(id);
215         ComponentDepsNode *comp_node = id_node->add_component(comp_type, comp_name);
216         comp_node->owner = id_node;
217         return comp_node;
218 }
219
220 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
221         ComponentDepsNode *comp_node,
222         eDepsOperation_Type optype,
223         DepsEvalOperationCb op,
224         eDepsOperation_Code opcode,
225         const char *name,
226         int name_tag)
227 {
228         OperationDepsNode *op_node = comp_node->has_operation(opcode,
229                                                               name,
230                                                               name_tag);
231         if (op_node == NULL) {
232                 op_node = comp_node->add_operation(optype, op, opcode, name, name_tag);
233                 m_graph->operations.push_back(op_node);
234         }
235         else {
236                 fprintf(stderr,
237                         "add_operation: Operation already exists - %s has %s at %p\n",
238                         comp_node->identifier().c_str(),
239                         op_node->identifier().c_str(),
240                         op_node);
241                 BLI_assert(!"Should not happen!");
242         }
243         return op_node;
244 }
245
246 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
247         ID *id,
248         eDepsNode_Type comp_type,
249         const char *comp_name,
250         eDepsOperation_Type optype,
251         DepsEvalOperationCb op,
252         eDepsOperation_Code opcode,
253         const char *name,
254         int name_tag)
255 {
256         ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
257         return add_operation_node(comp_node, optype, op, opcode, name, name_tag);
258 }
259
260 OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
261         ID *id,
262         eDepsNode_Type comp_type,
263         eDepsOperation_Type optype,
264         DepsEvalOperationCb op,
265         eDepsOperation_Code opcode,
266         const char *name,
267         int name_tag)
268 {
269         return add_operation_node(id,
270                                   comp_type,
271                                   "",
272                                   optype,
273                                   op,
274                                   opcode,
275                                   name,
276                                   name_tag);
277 }
278
279 bool DepsgraphNodeBuilder::has_operation_node(ID *id,
280                                               eDepsNode_Type comp_type,
281                                               const char *comp_name,
282                                               eDepsOperation_Code opcode,
283                                               const char *name,
284                                               int name_tag)
285 {
286         return find_operation_node(id,
287                                    comp_type,
288                                    comp_name,
289                                    opcode,
290                                    name,
291                                    name_tag) != NULL;
292 }
293
294 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
295         ID *id,
296         eDepsNode_Type comp_type,
297         const char *comp_name,
298         eDepsOperation_Code opcode,
299         const char *name,
300         int name_tag)
301 {
302         ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
303         return comp_node->has_operation(opcode, name, name_tag);
304 }
305
306 OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
307         ID *id,
308         eDepsNode_Type comp_type,
309         eDepsOperation_Code opcode,
310         const char *name,
311         int name_tag)
312 {
313         return find_operation_node(id, comp_type, "", opcode, name, name_tag);
314 }
315
316 /* **** Build functions for entity nodes **** */
317
318 void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene)
319 {
320         /* LIB_TAG_DOIT is used to indicate whether node for given ID was already
321          * created or not. This flag is being set in add_id_node(), so functions
322          * shouldn't bother with setting it, they only might query this flag when
323          * needed.
324          */
325         BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
326         /* XXX nested node trees are not included in tag-clearing above,
327          * so we need to do this manually.
328          */
329         FOREACH_NODETREE(bmain, nodetree, id) {
330                 if (id != (ID *)nodetree)
331                         nodetree->id.tag &= ~LIB_TAG_DOIT;
332         } FOREACH_NODETREE_END
333
334         /* scene ID block */
335         add_id_node(&scene->id);
336
337         /* timesource */
338         add_time_source(NULL);
339
340         /* build subgraph for set, and link this in... */
341         // XXX: depending on how this goes, that scene itself could probably store its
342         //      own little partial depsgraph?
343         if (scene->set) {
344                 build_scene(bmain, scene->set);
345         }
346
347         /* scene objects */
348         for (Base *base = (Base *)scene->base.first; base; base = base->next) {
349                 Object *ob = base->object;
350
351                 /* object itself */
352                 build_object(scene, base, ob);
353
354                 /* object that this is a proxy for */
355                 // XXX: the way that proxies work needs to be completely reviewed!
356                 if (ob->proxy) {
357                         ob->proxy->proxy_from = ob;
358                         build_object(scene, base, ob->proxy);
359                 }
360
361                 /* Object dupligroup. */
362                 if (ob->dup_group) {
363                         build_group(scene, base, ob->dup_group);
364                 }
365         }
366
367         /* rigidbody */
368         if (scene->rigidbody_world) {
369                 build_rigidbody(scene);
370         }
371
372         /* scene's animation and drivers */
373         if (scene->adt) {
374                 build_animdata(&scene->id);
375         }
376
377         /* world */
378         if (scene->world) {
379                 build_world(scene->world);
380         }
381
382         /* compo nodes */
383         if (scene->nodetree) {
384                 build_compositor(scene);
385         }
386
387         /* sequencer */
388         // XXX...
389
390         /* grease pencil */
391         if (scene->gpd) {
392                 build_gpencil(scene->gpd);
393         }
394
395         /* cache files */
396         for (CacheFile *cachefile = static_cast<CacheFile *>(bmain->cachefiles.first);
397              cachefile;
398              cachefile = static_cast<CacheFile *>(cachefile->id.next))
399         {
400                 build_cachefile(cachefile);
401         }
402 }
403
404 void DepsgraphNodeBuilder::build_group(Scene *scene,
405                                        Base *base,
406                                        Group *group)
407 {
408         ID *group_id = &group->id;
409         if (group_id->tag & LIB_TAG_DOIT) {
410                 return;
411         }
412         group_id->tag |= LIB_TAG_DOIT;
413
414         for (GroupObject *go = (GroupObject *)group->gobject.first;
415              go != NULL;
416              go = go->next)
417         {
418                 build_object(scene, base, go->ob);
419         }
420 }
421
422 SubgraphDepsNode *DepsgraphNodeBuilder::build_subgraph(Group *group)
423 {
424         /* sanity checks */
425         if (!group)
426                 return NULL;
427
428         /* create new subgraph's data */
429         Depsgraph *subgraph = reinterpret_cast<Depsgraph *>(DEG_graph_new());
430
431         DepsgraphNodeBuilder subgraph_builder(m_bmain, subgraph);
432
433         /* add group objects */
434         for (GroupObject *go = (GroupObject *)group->gobject.first;
435              go != NULL;
436              go = go->next)
437         {
438                 /*Object *ob = go->ob;*/
439
440                 /* Each "group object" is effectively a separate instance of the
441                  * underlying object data. When the group is evaluated, the transform
442                  * results and/or some other attributes end up getting overridden by
443                  * the group.
444                  */
445         }
446
447         /* Create a node for representing subgraph. */
448         SubgraphDepsNode *subgraph_node = m_graph->add_subgraph_node(&group->id);
449         subgraph_node->graph = subgraph;
450
451         /* Make a copy of the data this node will need? */
452         /* XXX: do we do this now, or later? */
453         /* TODO: need API function which queries graph's ID's hash, and duplicates
454          * those blocks thoroughly with all outside links removed.
455          */
456
457         return subgraph_node;
458 }
459
460 void DepsgraphNodeBuilder::build_object(Scene *scene, Base *base, Object *ob)
461 {
462         if (ob->id.tag & LIB_TAG_DOIT) {
463                 IDDepsNode *id_node = m_graph->find_id_node(&ob->id);
464                 if (base != NULL) {
465                         id_node->layers |= base->lay;
466                 }
467                 return;
468         }
469         ob->id.tag |= LIB_TAG_DOIT;
470
471         IDDepsNode *id_node = add_id_node(&ob->id);
472         if (base != NULL) {
473                 id_node->layers |= base->lay;
474         }
475         ob->customdata_mask = 0;
476
477         /* Standard components. */
478         build_object_transform(scene, ob);
479
480         if (ob->parent != NULL) {
481                 build_object(scene, NULL, ob->parent);
482         }
483         if (ob->modifiers.first != NULL) {
484                 BuilderWalkUserData data;
485                 data.builder = this;
486                 data.scene = scene;
487                 modifiers_foreachObjectLink(ob, modifier_walk, &data);
488         }
489         if (ob->constraints.first != NULL) {
490                 BuilderWalkUserData data;
491                 data.builder = this;
492                 data.scene = scene;
493                 modifiers_foreachObjectLink(ob, modifier_walk, &data);
494                 BKE_constraints_id_loop(&ob->constraints, constraint_walk, &data);
495         }
496
497         /* Object data. */
498         if (ob->data) {
499                 /* type-specific data... */
500                 switch (ob->type) {
501                         case OB_MESH:     /* Geometry */
502                         case OB_CURVE:
503                         case OB_FONT:
504                         case OB_SURF:
505                         case OB_MBALL:
506                         case OB_LATTICE:
507                                 build_obdata_geom(scene, ob);
508                                 /* TODO(sergey): Only for until we support granular
509                                  * update of curves.
510                                  */
511                                 if (ob->type == OB_FONT) {
512                                         Curve *curve = (Curve *)ob->data;
513                                         if (curve->textoncurve) {
514                                                 id_node->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
515                                         }
516                                 }
517                                 break;
518
519                         case OB_ARMATURE: /* Pose */
520                                 if (ID_IS_LINKED_DATABLOCK(ob) && ob->proxy_from != NULL) {
521                                         build_proxy_rig(ob);
522                                 }
523                                 else {
524                                         build_rig(scene, ob);
525                                 }
526                                 break;
527
528                         case OB_LAMP:   /* Lamp */
529                                 build_lamp(ob);
530                                 break;
531
532                         case OB_CAMERA: /* Camera */
533                                 build_camera(ob);
534                                 break;
535
536                         default:
537                         {
538                                 ID *obdata = (ID *)ob->data;
539                                 if ((obdata->tag & LIB_TAG_DOIT) == 0) {
540                                         build_animdata(obdata);
541                                 }
542                                 break;
543                         }
544                 }
545         }
546
547         /* Build animation data,
548          *
549          * Do it now because it's possible object data will affect
550          * on object's level animation, for example in case of rebuilding
551          * pose for proxy.
552          */
553         build_animdata(&ob->id);
554
555         /* grease pencil */
556         if (ob->gpd) {
557                 build_gpencil(ob->gpd);
558         }
559 }
560
561 void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob)
562 {
563         /* local transforms (from transform channels - loc/rot/scale + deltas) */
564         add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
565                            DEPSOP_TYPE_INIT, function_bind(BKE_object_eval_local_transform, _1, scene, ob),
566                            DEG_OPCODE_TRANSFORM_LOCAL);
567
568         /* object parent */
569         if (ob->parent) {
570                 add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
571                                    DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_parent, _1, scene, ob),
572                                    DEG_OPCODE_TRANSFORM_PARENT);
573         }
574
575         /* object constraints */
576         if (ob->constraints.first) {
577                 build_object_constraints(scene, ob);
578         }
579
580         /* Temporary uber-update node, which does everything.
581          * It is for the being we're porting old dependencies into the new system.
582          * We'll get rid of this node as soon as all the granular update functions
583          * are filled in.
584          *
585          * TODO(sergey): Get rid of this node.
586          */
587         add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
588                            DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_uber_transform, _1, scene, ob),
589                            DEG_OPCODE_OBJECT_UBEREVAL);
590
591         /* object transform is done */
592         add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
593                            DEPSOP_TYPE_POST, function_bind(BKE_object_eval_done, _1, ob),
594                            DEG_OPCODE_TRANSFORM_FINAL);
595 }
596
597 /**
598  * Constraints Graph Notes
599  *
600  * For constraints, we currently only add a operation node to the Transform
601  * or Bone components (depending on whichever type of owner we have).
602  * This represents the entire constraints stack, which is for now just
603  * executed as a single monolithic block. At least initially, this should
604  * be sufficient for ensuring that the porting/refactoring process remains
605  * manageable.
606  *
607  * However, when the time comes for developing "node-based" constraints,
608  * we'll need to split this up into pre/post nodes for "constraint stack
609  * evaluation" + operation nodes for each constraint (i.e. the contents
610  * of the loop body used in the current "solve_constraints()" operation).
611  *
612  * -- Aligorith, August 2013
613  */
614 void DepsgraphNodeBuilder::build_object_constraints(Scene *scene, Object *ob)
615 {
616         /* create node for constraint stack */
617         add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
618                            DEPSOP_TYPE_EXEC, function_bind(BKE_object_eval_constraints, _1, scene, ob),
619                            DEG_OPCODE_TRANSFORM_CONSTRAINTS);
620 }
621
622 void DepsgraphNodeBuilder::build_pose_constraints(Object *ob, bPoseChannel *pchan)
623 {
624         /* create node for constraint stack */
625         add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
626                            DEPSOP_TYPE_EXEC, function_bind(BKE_pose_constraints_evaluate, _1, ob, pchan),
627                            DEG_OPCODE_BONE_CONSTRAINTS);
628 }
629
630 /**
631  * Build graph nodes for AnimData block
632  * \param id: ID-Block which hosts the AnimData
633  */
634 void DepsgraphNodeBuilder::build_animdata(ID *id)
635 {
636         AnimData *adt = BKE_animdata_from_id(id);
637
638         if (adt == NULL)
639                 return;
640
641         /* animation */
642         if (adt->action || adt->nla_tracks.first || adt->drivers.first) {
643                 // XXX: Hook up specific update callbacks for special properties which may need it...
644
645                 /* actions and NLA - as a single unit for now, as it gets complicated to schedule otherwise */
646                 if ((adt->action) || (adt->nla_tracks.first)) {
647                         /* create the node */
648                         add_operation_node(id, DEPSNODE_TYPE_ANIMATION,
649                                            DEPSOP_TYPE_EXEC, function_bind(BKE_animsys_eval_animdata, _1, id),
650                                            DEG_OPCODE_ANIMATION, id->name);
651
652                         // TODO: for each channel affected, we might also want to add some support for running RNA update callbacks on them
653                         // (which will be needed for proper handling of drivers later)
654                 }
655
656                 /* drivers */
657                 for (FCurve *fcu = (FCurve *)adt->drivers.first; fcu; fcu = fcu->next) {
658                         /* create driver */
659                         build_driver(id, fcu);
660                 }
661         }
662 }
663
664 /**
665  * Build graph node(s) for Driver
666  * \param id: ID-Block that driver is attached to
667  * \param fcu: Driver-FCurve
668  */
669 OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu)
670 {
671         ChannelDriver *driver = fcu->driver;
672
673         /* Create data node for this driver */
674         /* TODO(sergey): Avoid creating same operation multiple times,
675          * in the future we need to avoid lookup of the operation as well
676          * and use some tagging magic instead.
677          */
678         OperationDepsNode *driver_op = find_operation_node(id,
679                                                            DEPSNODE_TYPE_PARAMETERS,
680                                                            DEG_OPCODE_DRIVER,
681                                                            fcu->rna_path,
682                                                            fcu->array_index);
683
684         if (driver_op == NULL) {
685                 driver_op = add_operation_node(id,
686                                                DEPSNODE_TYPE_PARAMETERS,
687                                                DEPSOP_TYPE_EXEC,
688                                                function_bind(BKE_animsys_eval_driver, _1, id, fcu),
689                                                DEG_OPCODE_DRIVER,
690                                                fcu->rna_path,
691                                                fcu->array_index);
692         }
693
694         /* tag "scripted expression" drivers as needing Python (due to GIL issues, etc.) */
695         if (driver->type == DRIVER_TYPE_PYTHON) {
696                 driver_op->flag |= DEPSOP_FLAG_USES_PYTHON;
697         }
698
699         /* return driver node created */
700         return driver_op;
701 }
702
703 /* Recursively build graph for world */
704 void DepsgraphNodeBuilder::build_world(World *world)
705 {
706         ID *world_id = &world->id;
707         if (world_id->tag & LIB_TAG_DOIT) {
708                 return;
709         }
710
711         /* world itself */
712         IDDepsNode *world_node = add_id_node(world_id); /* world shading/params? */
713
714         build_animdata(world_id);
715
716         /* TODO: other settings? */
717
718         /* textures */
719         build_texture_stack(world_node, world->mtex);
720
721         /* world's nodetree */
722         if (world->nodetree) {
723                 build_nodetree(world_node, world->nodetree);
724         }
725 }
726
727 /* Rigidbody Simulation - Scene Level */
728 void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
729 {
730         RigidBodyWorld *rbw = scene->rigidbody_world;
731
732         /**
733          * Rigidbody Simulation Nodes
734          * ==========================
735          *
736          * There are 3 nodes related to Rigidbody Simulation:
737          * 1) "Initialize/Rebuild World" - this is called sparingly, only when the simulation
738          *    needs to be rebuilt (mainly after file reload, or moving back to start frame)
739          * 2) "Do Simulation" - perform a simulation step - interleaved between the evaluation
740          *    steps for clusters of objects (i.e. between those affected and/or not affected by
741          *    the sim for instance)
742          *
743          * 3) "Pull Results" - grab the specific transforms applied for a specific object -
744          *    performed as part of object's transform-stack building
745          */
746
747         /* create nodes ------------------------------------------------------------------------ */
748         /* XXX: is this the right component, or do we want to use another one instead? */
749
750         /* init/rebuild operation */
751         /*OperationDepsNode *init_node =*/ add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM,
752                                                               DEPSOP_TYPE_REBUILD, function_bind(BKE_rigidbody_rebuild_sim, _1, scene),
753                                                               DEG_OPCODE_RIGIDBODY_REBUILD);
754
755         /* do-sim operation */
756         // XXX: what happens if we need to split into several groups?
757         OperationDepsNode *sim_node     = add_operation_node(&scene->id, DEPSNODE_TYPE_TRANSFORM,
758                                                              DEPSOP_TYPE_SIM, function_bind(BKE_rigidbody_eval_simulation, _1, scene),
759                                                              DEG_OPCODE_RIGIDBODY_SIM);
760
761         /* XXX: For now, the sim node is the only one that really matters here. If any other
762          * sims get added later, we may have to remove these hacks...
763          */
764         sim_node->owner->entry_operation = sim_node;
765         sim_node->owner->exit_operation  = sim_node;
766
767
768         /* objects - simulation participants */
769         if (rbw->group) {
770                 for (GroupObject *go = (GroupObject *)rbw->group->gobject.first; go; go = go->next) {
771                         Object *ob = go->ob;
772
773                         if (!ob || (ob->type != OB_MESH))
774                                 continue;
775
776                         /* 2) create operation for flushing results */
777                         /* object's transform component - where the rigidbody operation lives */
778                         add_operation_node(&ob->id, DEPSNODE_TYPE_TRANSFORM,
779                                            DEPSOP_TYPE_EXEC, function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, ob),
780                                            DEG_OPCODE_TRANSFORM_RIGIDBODY);
781                 }
782         }
783 }
784
785 /* IK Solver Eval Steps */
786 void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
787 {
788         bKinematicConstraint *data = (bKinematicConstraint *)con->data;
789
790         /* Find the chain's root. */
791         bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data);
792
793         if (has_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
794                                DEG_OPCODE_POSE_IK_SOLVER))
795         {
796                 return;
797         }
798
799         /* Operation node for evaluating/running IK Solver. */
800         add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
801                            DEPSOP_TYPE_SIM, function_bind(BKE_pose_iktree_evaluate, _1, scene, ob, rootchan),
802                            DEG_OPCODE_POSE_IK_SOLVER);
803 }
804
805 /* Spline IK Eval Steps */
806 void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
807 {
808         bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
809
810         /* Find the chain's root. */
811         bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
812
813         /* Operation node for evaluating/running Spline IK Solver.
814          * Store the "root bone" of this chain in the solver, so it knows where to start.
815          */
816         add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
817                            DEPSOP_TYPE_SIM, function_bind(BKE_pose_splineik_evaluate, _1, scene, ob, rootchan),
818                            DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
819 }
820
821 /* Pose/Armature Bones Graph */
822 void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob)
823 {
824         bArmature *arm = (bArmature *)ob->data;
825
826         /* animation and/or drivers linking posebones to base-armature used to define them
827          * NOTE: AnimData here is really used to control animated deform properties,
828          *       which ideally should be able to be unique across different instances.
829          *       Eventually, we need some type of proxy/isolation mechanism in-between here
830          *       to ensure that we can use same rig multiple times in same scene...
831          */
832         build_animdata(&arm->id);
833
834         /* Rebuild pose if not up to date. */
835         if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) {
836                 BKE_pose_rebuild_ex(ob, arm, false);
837                 /* XXX: Without this animation gets lost in certain circumstances
838                  * after loading file. Need to investigate further since it does
839                  * not happen with simple scenes..
840                  */
841                 if (ob->adt) {
842                         ob->adt->recalc |= ADT_RECALC_ANIM;
843                 }
844         }
845
846         /* speed optimization for animation lookups */
847         if (ob->pose) {
848                 BKE_pose_channels_hash_make(ob->pose);
849                 if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
850                         BKE_pose_update_constraint_flags(ob->pose);
851                 }
852         }
853
854         /* Make sure pose is up-to-date with armature updates. */
855         add_operation_node(&arm->id,
856                            DEPSNODE_TYPE_PARAMETERS,
857                            DEPSOP_TYPE_EXEC,
858                            NULL,
859                            DEG_OPCODE_PLACEHOLDER,
860                            "Armature Eval");
861
862         /**
863          * Pose Rig Graph
864          * ==============
865          *
866          * Pose Component:
867          * - Mainly used for referencing Bone components.
868          * - This is where the evaluation operations for init/exec/cleanup
869          *   (ik) solvers live, and are later hooked up (so that they can be
870          *   interleaved during runtime) with bone-operations they depend on/affect.
871          * - init_pose_eval() and cleanup_pose_eval() are absolute first and last
872          *   steps of pose eval process. ALL bone operations must be performed
873          *   between these two...
874          *
875          * Bone Component:
876          * - Used for representing each bone within the rig
877          * - Acts to encapsulate the evaluation operations (base matrix + parenting,
878          *   and constraint stack) so that they can be easily found.
879          * - Everything else which depends on bone-results hook up to the component only
880          *   so that we can redirect those to point at either the the post-IK/
881          *   post-constraint/post-matrix steps, as needed.
882          */
883
884         /* pose eval context */
885         add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE,
886                            DEPSOP_TYPE_INIT, function_bind(BKE_pose_eval_init, _1, scene, ob, ob->pose), DEG_OPCODE_POSE_INIT);
887
888         add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE,
889                            DEPSOP_TYPE_POST, function_bind(BKE_pose_eval_flush, _1, scene, ob, ob->pose), DEG_OPCODE_POSE_DONE);
890
891         /* bones */
892         for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) {
893                 /* node for bone eval */
894                 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
895                                    DEPSOP_TYPE_INIT, NULL, // XXX: BKE_pose_eval_bone_local
896                                    DEG_OPCODE_BONE_LOCAL);
897
898                 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
899                                    DEPSOP_TYPE_EXEC, function_bind(BKE_pose_eval_bone, _1, scene, ob, pchan), // XXX: BKE_pose_eval_bone_pose
900                                    DEG_OPCODE_BONE_POSE_PARENT);
901
902                 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
903                                    DEPSOP_TYPE_OUT, NULL, /* NOTE: dedicated noop for easier relationship construction */
904                                    DEG_OPCODE_BONE_READY);
905
906                 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
907                                    DEPSOP_TYPE_POST, function_bind(BKE_pose_bone_done, _1, pchan),
908                                    DEG_OPCODE_BONE_DONE);
909
910                 /* constraints */
911                 if (pchan->constraints.first != NULL) {
912                         build_pose_constraints(ob, pchan);
913                 }
914
915                 /**
916                  * IK Solvers...
917                  *
918                  * - These require separate processing steps are pose-level
919                  *   to be executed between chains of bones (i.e. once the
920                  *   base transforms of a bunch of bones is done)
921                  *
922                  * Unsolved Issues:
923                  * - Care is needed to ensure that multi-headed trees work out the same as in ik-tree building
924                  * - Animated chain-lengths are a problem...
925                  */
926                 for (bConstraint *con = (bConstraint *)pchan->constraints.first; con; con = con->next) {
927                         switch (con->type) {
928                                 case CONSTRAINT_TYPE_KINEMATIC:
929                                         build_ik_pose(scene, ob, pchan, con);
930                                         break;
931
932                                 case CONSTRAINT_TYPE_SPLINEIK:
933                                         build_splineik_pose(scene, ob, pchan, con);
934                                         break;
935
936                                 default:
937                                         break;
938                         }
939                 }
940         }
941 }
942
943 void DepsgraphNodeBuilder::build_proxy_rig(Object *ob)
944 {
945         ID *obdata = (ID *)ob->data;
946         build_animdata(obdata);
947
948         BLI_assert(ob->pose != NULL);
949
950         /* speed optimization for animation lookups */
951         BKE_pose_channels_hash_make(ob->pose);
952         if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
953                 BKE_pose_update_constraint_flags(ob->pose);
954         }
955
956         add_operation_node(&ob->id,
957                            DEPSNODE_TYPE_EVAL_POSE,
958                            DEPSOP_TYPE_INIT,
959                            function_bind(BKE_pose_eval_proxy_copy, _1, ob),
960                            DEG_OPCODE_POSE_INIT);
961
962         for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first;
963              pchan != NULL;
964              pchan = pchan->next)
965         {
966                 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
967                                    DEPSOP_TYPE_INIT, NULL,
968                                    DEG_OPCODE_BONE_LOCAL);
969
970                 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
971                                    DEPSOP_TYPE_EXEC, NULL,
972                                    DEG_OPCODE_BONE_READY);
973
974                 add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
975                                    DEPSOP_TYPE_POST, NULL,
976                                    DEG_OPCODE_BONE_DONE);
977         }
978
979         add_operation_node(&ob->id,
980                            DEPSNODE_TYPE_EVAL_POSE,
981                            DEPSOP_TYPE_POST,
982                            NULL,
983                            DEG_OPCODE_POSE_DONE);
984 }
985
986 /* Shapekeys */
987 void DepsgraphNodeBuilder::build_shapekeys(Key *key)
988 {
989         build_animdata(&key->id);
990
991         add_operation_node(&key->id, DEPSNODE_TYPE_GEOMETRY, DEPSOP_TYPE_EXEC, NULL,
992                            DEG_OPCODE_PLACEHOLDER, "Shapekey Eval");
993 }
994
995 /* ObData Geometry Evaluation */
996 // XXX: what happens if the datablock is shared!
997 void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
998 {
999         ID *obdata = (ID *)ob->data;
1000
1001         /* TODO(sergey): This way using this object's properties as driver target
1002          * works fine.
1003          *
1004          * Does this depend on other nodes?
1005          */
1006         add_operation_node(&ob->id,
1007                            DEPSNODE_TYPE_PARAMETERS,
1008                            DEPSOP_TYPE_POST,
1009                            NULL,
1010                            DEG_OPCODE_PLACEHOLDER,
1011                            "Parameters Eval");
1012
1013         /* Temporary uber-update node, which does everything.
1014          * It is for the being we're porting old dependencies into the new system.
1015          * We'll get rid of this node as soon as all the granular update functions
1016          * are filled in.
1017          *
1018          * TODO(sergey): Get rid of this node.
1019          */
1020         add_operation_node(&ob->id,
1021                            DEPSNODE_TYPE_GEOMETRY,
1022                            DEPSOP_TYPE_POST,
1023                            function_bind(BKE_object_eval_uber_data, _1, scene, ob),
1024                            DEG_OPCODE_GEOMETRY_UBEREVAL);
1025
1026         add_operation_node(&ob->id,
1027                            DEPSNODE_TYPE_GEOMETRY,
1028                            DEPSOP_TYPE_INIT,
1029                            NULL,
1030                            DEG_OPCODE_PLACEHOLDER,
1031                            "Eval Init");
1032
1033         // TODO: "Done" operation
1034
1035         /* Modifiers */
1036         if (ob->modifiers.first) {
1037                 for (ModifierData *md = (ModifierData *)ob->modifiers.first;
1038                      md != NULL;
1039                      md = md->next)
1040                 {
1041                         add_operation_node(&ob->id,
1042                                            DEPSNODE_TYPE_GEOMETRY,
1043                                            DEPSOP_TYPE_EXEC,
1044                                            function_bind(BKE_object_eval_modifier,
1045                                                          _1,
1046                                                          scene,
1047                                                          ob,
1048                                                          md),
1049                                            DEG_OPCODE_GEOMETRY_MODIFIER,
1050                                            md->name);
1051                 }
1052         }
1053
1054         /* materials */
1055         if (ob->totcol) {
1056                 for (int a = 1; a <= ob->totcol; a++) {
1057                         Material *ma = give_current_material(ob, a);
1058                         if (ma != NULL) {
1059                                 // XXX?!
1060                                 ComponentDepsNode *geom_node = add_component_node(&ob->id, DEPSNODE_TYPE_GEOMETRY);
1061                                 build_material(geom_node, ma);
1062                         }
1063                 }
1064         }
1065
1066         /* geometry collision */
1067         if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1068                 // add geometry collider relations
1069         }
1070
1071         if (obdata->tag & LIB_TAG_DOIT) {
1072                 return;
1073         }
1074
1075         /* ShapeKeys */
1076         Key *key = BKE_key_from_object(ob);
1077         if (key) {
1078                 build_shapekeys(key);
1079         }
1080
1081         build_animdata(obdata);
1082
1083         /* Nodes for result of obdata's evaluation, and geometry
1084          * evaluation on object.
1085          */
1086         switch (ob->type) {
1087                 case OB_MESH:
1088                 {
1089                         //Mesh *me = (Mesh *)ob->data;
1090
1091                         /* evaluation operations */
1092                         add_operation_node(obdata,
1093                                            DEPSNODE_TYPE_GEOMETRY,
1094                                            DEPSOP_TYPE_INIT,
1095                                            function_bind(BKE_mesh_eval_geometry,
1096                                                          _1,
1097                                                          (Mesh *)obdata),
1098                                            DEG_OPCODE_PLACEHOLDER,
1099                                            "Geometry Eval");
1100                         break;
1101                 }
1102
1103                 case OB_MBALL:
1104                 {
1105                         Object *mom = BKE_mball_basis_find(scene, ob);
1106
1107                         /* Motherball - mom depends on children! */
1108                         if (mom == ob) {
1109                                 /* metaball evaluation operations */
1110                                 /* NOTE: only the motherball gets evaluated! */
1111                                 add_operation_node(obdata,
1112                                                    DEPSNODE_TYPE_GEOMETRY,
1113                                                    DEPSOP_TYPE_INIT,
1114                                                    function_bind(BKE_mball_eval_geometry,
1115                                                                  _1,
1116                                                                  (MetaBall *)obdata),
1117                                                    DEG_OPCODE_PLACEHOLDER,
1118                                                    "Geometry Eval");
1119                         }
1120                         break;
1121                 }
1122
1123                 case OB_CURVE:
1124                 case OB_SURF:
1125                 case OB_FONT:
1126                 {
1127                         /* Curve/nurms evaluation operations. */
1128                         /* - calculate curve geometry (including path) */
1129                         add_operation_node(obdata,
1130                                            DEPSNODE_TYPE_GEOMETRY,
1131                                            DEPSOP_TYPE_INIT,
1132                                            function_bind(BKE_curve_eval_geometry,
1133                                                          _1,
1134                                                          (Curve *)obdata),
1135                                            DEG_OPCODE_PLACEHOLDER,
1136                                            "Geometry Eval");
1137
1138                         /* Calculate curve path - this is used by constraints, etc. */
1139                         if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
1140                                 add_operation_node(obdata,
1141                                                    DEPSNODE_TYPE_GEOMETRY,
1142                                                    DEPSOP_TYPE_EXEC,
1143                                                    function_bind(BKE_curve_eval_path,
1144                                                                  _1,
1145                                                                  (Curve *)obdata),
1146                                                    DEG_OPCODE_GEOMETRY_PATH,
1147                                                    "Path");
1148                         }
1149
1150                         /* Make sure objects used for bevel.taper are in the graph.
1151                          * NOTE: This objects might be not linked to the scene.
1152                          */
1153                         Curve *cu = (Curve *)obdata;
1154                         if (cu->bevobj != NULL) {
1155                                 build_object(scene, NULL, cu->bevobj);
1156                         }
1157                         if (cu->taperobj != NULL) {
1158                                 build_object(scene, NULL, cu->bevobj);
1159                         }
1160                         if (ob->type == OB_FONT && cu->textoncurve != NULL) {
1161                                 build_object(scene, NULL, cu->textoncurve);
1162                         }
1163                         break;
1164                 }
1165
1166                 case OB_LATTICE:
1167                 {
1168                         /* Lattice evaluation operations. */
1169                         add_operation_node(obdata,
1170                                            DEPSNODE_TYPE_GEOMETRY,
1171                                            DEPSOP_TYPE_INIT,
1172                                            function_bind(BKE_lattice_eval_geometry,
1173                                                          _1,
1174                                                          (Lattice *)obdata),
1175                                            DEG_OPCODE_PLACEHOLDER,
1176                                            "Geometry Eval");
1177                         break;
1178                 }
1179         }
1180
1181         add_operation_node(obdata, DEPSNODE_TYPE_GEOMETRY,
1182                            DEPSOP_TYPE_POST, NULL,
1183                            DEG_OPCODE_PLACEHOLDER, "Eval Done");
1184
1185         /* Parameters for driver sources. */
1186         add_operation_node(obdata, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL,
1187                            DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1188 }
1189
1190 /* Cameras */
1191 void DepsgraphNodeBuilder::build_camera(Object *ob)
1192 {
1193         /* TODO: Link scene-camera links in somehow... */
1194         Camera *cam = (Camera *)ob->data;
1195         ID *camera_id = &cam->id;
1196         if (camera_id->tag & LIB_TAG_DOIT) {
1197                 return;
1198         }
1199
1200         build_animdata(&cam->id);
1201
1202         add_operation_node(camera_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL,
1203                            DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1204
1205         if (cam->dof_ob != NULL) {
1206                 /* TODO(sergey): For now parametrs are on object level. */
1207                 add_operation_node(&ob->id, DEPSNODE_TYPE_PARAMETERS,
1208                                    DEPSOP_TYPE_EXEC, NULL,
1209                                    DEG_OPCODE_PLACEHOLDER,
1210                                    "Camera DOF");
1211         }
1212 }
1213
1214 /* Lamps */
1215 void DepsgraphNodeBuilder::build_lamp(Object *ob)
1216 {
1217         Lamp *la = (Lamp *)ob->data;
1218         ID *lamp_id = &la->id;
1219         if (lamp_id->tag & LIB_TAG_DOIT) {
1220                 return;
1221         }
1222
1223         build_animdata(&la->id);
1224
1225         /* node for obdata */
1226         ComponentDepsNode *param_node = add_component_node(lamp_id, DEPSNODE_TYPE_PARAMETERS);
1227
1228         /* TODO(sergey): Is it really how we're supposed to work with drivers? */
1229         add_operation_node(lamp_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_EXEC, NULL,
1230                            DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1231
1232         /* lamp's nodetree */
1233         if (la->nodetree) {
1234                 build_nodetree(param_node, la->nodetree);
1235         }
1236
1237         /* textures */
1238         build_texture_stack(param_node, la->mtex);
1239 }
1240
1241 void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree)
1242 {
1243         if (!ntree)
1244                 return;
1245
1246         /* nodetree itself */
1247         ID *ntree_id = &ntree->id;
1248
1249         build_animdata(ntree_id);
1250
1251         /* Parameters for drivers. */
1252         add_operation_node(ntree_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_POST, NULL,
1253                            DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
1254
1255         /* nodetree's nodes... */
1256         for (bNode *bnode = (bNode *)ntree->nodes.first; bnode; bnode = bnode->next) {
1257                 ID *id = bnode->id;
1258                 if (id != NULL) {
1259                         short id_type = GS(id->name);
1260                         if (id_type == ID_MA) {
1261                                 build_material(owner_node, (Material *)id);
1262                         }
1263                         else if (id_type == ID_TE) {
1264                                 build_texture(owner_node, (Tex *)id);
1265                         }
1266                         else if (id_type == ID_IM) {
1267                                 build_image((Image *)id);
1268                         }
1269                         else if (bnode->type == NODE_GROUP) {
1270                                 bNodeTree *group_ntree = (bNodeTree *)id;
1271                                 if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) {
1272                                         build_nodetree(owner_node, group_ntree);
1273                                 }
1274                         }
1275                 }
1276         }
1277
1278         // TODO: link from nodetree to owner_component?
1279 }
1280
1281 /* Recursively build graph for material */
1282 void DepsgraphNodeBuilder::build_material(DepsNode *owner_node, Material *ma)
1283 {
1284         ID *ma_id = &ma->id;
1285         if (ma_id->tag & LIB_TAG_DOIT) {
1286                 return;
1287         }
1288
1289         /* material itself */
1290         add_id_node(ma_id);
1291
1292         add_operation_node(ma_id, DEPSNODE_TYPE_SHADING,
1293                            DEPSOP_TYPE_EXEC, NULL,
1294                            DEG_OPCODE_PLACEHOLDER, "Material Update");
1295
1296         /* material animation */
1297         build_animdata(ma_id);
1298
1299         /* textures */
1300         build_texture_stack(owner_node, ma->mtex);
1301
1302         /* material's nodetree */
1303         build_nodetree(owner_node, ma->nodetree);
1304 }
1305
1306 /* Texture-stack attached to some shading datablock */
1307 void DepsgraphNodeBuilder::build_texture_stack(DepsNode *owner_node, MTex **texture_stack)
1308 {
1309         int i;
1310
1311         /* for now assume that all texture-stacks have same number of max items */
1312         for (i = 0; i < MAX_MTEX; i++) {
1313                 MTex *mtex = texture_stack[i];
1314                 if (mtex && mtex->tex)
1315                         build_texture(owner_node, mtex->tex);
1316         }
1317 }
1318
1319 /* Recursively build graph for texture */
1320 void DepsgraphNodeBuilder::build_texture(DepsNode *owner_node, Tex *tex)
1321 {
1322         ID *tex_id = &tex->id;
1323         if (tex_id->tag & LIB_TAG_DOIT) {
1324                 return;
1325         }
1326         tex_id->tag |= LIB_TAG_DOIT;
1327         /* Texture itself. */
1328         build_animdata(tex_id);
1329         /* Texture's nodetree. */
1330         build_nodetree(owner_node, tex->nodetree);
1331         /* Special cases for different IDs which texture uses. */
1332         if (tex->type == TEX_IMAGE) {
1333                 if (tex->ima != NULL) {
1334                         build_image(tex->ima);
1335                 }
1336         }
1337 }
1338
1339 void DepsgraphNodeBuilder::build_image(Image *image) {
1340         ID *image_id = &image->id;
1341         if (image_id->tag & LIB_TAG_DOIT) {
1342                 return;
1343         }
1344         image_id->tag |= LIB_TAG_DOIT;
1345         /* Image ID node itself. */
1346         add_id_node(image_id);
1347         /* Placeholder so we can add relations and tag ID node for update. */
1348         add_operation_node(image_id,
1349                            DEPSNODE_TYPE_PARAMETERS,
1350                            DEPSOP_TYPE_EXEC,
1351                            NULL,
1352                            DEG_OPCODE_PLACEHOLDER,
1353                            "Image Eval");
1354 }
1355
1356 void DepsgraphNodeBuilder::build_compositor(Scene *scene)
1357 {
1358         /* For now, just a plain wrapper? */
1359         // TODO: create compositing component?
1360         // XXX: component type undefined!
1361         //graph->get_node(&scene->id, NULL, DEPSNODE_TYPE_COMPOSITING, NULL);
1362
1363         /* for now, nodetrees are just parameters; compositing occurs in internals of renderer... */
1364         ComponentDepsNode *owner_node = add_component_node(&scene->id, DEPSNODE_TYPE_PARAMETERS);
1365         build_nodetree(owner_node, scene->nodetree);
1366 }
1367
1368 void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd)
1369 {
1370         ID *gpd_id = &gpd->id;
1371
1372         /* gpencil itself */
1373         // XXX: what about multiple users of same datablock? This should only get added once
1374         add_id_node(gpd_id);
1375
1376         /* The main reason Grease Pencil is included here is because the animation (and drivers)
1377          * need to be hosted somewhere...
1378          */
1379         build_animdata(gpd_id);
1380 }
1381
1382 void DepsgraphNodeBuilder::build_cachefile(CacheFile *cache_file)
1383 {
1384         ID *cache_file_id = &cache_file->id;
1385
1386         add_component_node(cache_file_id, DEPSNODE_TYPE_CACHE);
1387
1388         add_operation_node(cache_file_id, DEPSNODE_TYPE_CACHE,
1389                            DEPSOP_TYPE_EXEC, NULL,
1390                            DEG_OPCODE_PLACEHOLDER, "Cache File Update");
1391
1392         add_id_node(cache_file_id);
1393         build_animdata(cache_file_id);
1394 }
1395
1396 }  // namespace DEG