Fix #33123: lamp nodes drivers not working, now uses same hacks as material

to work around dependency graph limitations.
This commit is contained in:
Brecht Van Lommel
2012-11-09 13:57:09 +00:00
parent 079a0a30e4
commit dc5ba03945
6 changed files with 84 additions and 12 deletions

View File

@@ -37,6 +37,7 @@ extern "C" {
#endif #endif
struct Lamp; struct Lamp;
struct Scene;
struct Lamp *BKE_lamp_add(const char *name) WARN_UNUSED; struct Lamp *BKE_lamp_add(const char *name) WARN_UNUSED;
struct Lamp *BKE_lamp_copy(struct Lamp *la) WARN_UNUSED; struct Lamp *BKE_lamp_copy(struct Lamp *la) WARN_UNUSED;
@@ -44,6 +45,8 @@ struct Lamp *localize_lamp(struct Lamp *la) WARN_UNUSED;
void BKE_lamp_make_local(struct Lamp *la); void BKE_lamp_make_local(struct Lamp *la);
void BKE_lamp_free(struct Lamp *la); void BKE_lamp_free(struct Lamp *la);
void lamp_drivers_update(struct Scene *scene, struct Lamp *la, float ctime);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -781,7 +781,7 @@ void BKE_animdata_main_cb(Main *mainptr, ID_AnimData_Edit_Callback func, void *u
ANIMDATA_NODETREE_IDS_CB(mainptr->tex.first, Tex); ANIMDATA_NODETREE_IDS_CB(mainptr->tex.first, Tex);
/* lamps */ /* lamps */
ANIMDATA_IDS_CB(mainptr->lamp.first); ANIMDATA_NODETREE_IDS_CB(mainptr->lamp.first, Lamp);
/* materials */ /* materials */
ANIMDATA_NODETREE_IDS_CB(mainptr->mat.first, Material); ANIMDATA_NODETREE_IDS_CB(mainptr->mat.first, Material);
@@ -823,7 +823,7 @@ void BKE_animdata_main_cb(Main *mainptr, ID_AnimData_Edit_Callback func, void *u
ANIMDATA_IDS_CB(mainptr->mask.first); ANIMDATA_IDS_CB(mainptr->mask.first);
/* worlds */ /* worlds */
ANIMDATA_IDS_CB(mainptr->world.first); ANIMDATA_NODETREE_IDS_CB(mainptr->world.first, World);
/* scenes */ /* scenes */
ANIMDATA_NODETREE_IDS_CB(mainptr->scene.first, Scene); ANIMDATA_NODETREE_IDS_CB(mainptr->scene.first, Scene);
@@ -868,7 +868,7 @@ void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const cha
RENAMEFIX_ANIM_NODETREE_IDS(mainptr->tex.first, Tex); RENAMEFIX_ANIM_NODETREE_IDS(mainptr->tex.first, Tex);
/* lamps */ /* lamps */
RENAMEFIX_ANIM_IDS(mainptr->lamp.first); RENAMEFIX_ANIM_NODETREE_IDS(mainptr->lamp.first, Lamp);
/* materials */ /* materials */
RENAMEFIX_ANIM_NODETREE_IDS(mainptr->mat.first, Material); RENAMEFIX_ANIM_NODETREE_IDS(mainptr->mat.first, Material);
@@ -910,7 +910,7 @@ void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const cha
RENAMEFIX_ANIM_IDS(mainptr->mask.first); RENAMEFIX_ANIM_IDS(mainptr->mask.first);
/* worlds */ /* worlds */
RENAMEFIX_ANIM_IDS(mainptr->world.first); RENAMEFIX_ANIM_NODETREE_IDS(mainptr->world.first, World);
/* scenes */ /* scenes */
RENAMEFIX_ANIM_NODETREE_IDS(mainptr->scene.first, Scene); RENAMEFIX_ANIM_NODETREE_IDS(mainptr->scene.first, Scene);

View File

@@ -45,6 +45,7 @@
#include "DNA_anim_types.h" #include "DNA_anim_types.h"
#include "DNA_camera_types.h" #include "DNA_camera_types.h"
#include "DNA_group_types.h" #include "DNA_group_types.h"
#include "DNA_lamp_types.h"
#include "DNA_lattice_types.h" #include "DNA_lattice_types.h"
#include "DNA_key_types.h" #include "DNA_key_types.h"
#include "DNA_material_types.h" #include "DNA_material_types.h"
@@ -350,8 +351,8 @@ static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node
/* XXX: forward def for material driver handling... */ /* XXX: forward def for material driver handling... */
static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma); static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma);
/* recursive handling for material nodetree drivers */ /* recursive handling for shader nodetree drivers */
static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree) static void dag_add_shader_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree)
{ {
bNode *n; bNode *n;
@@ -367,7 +368,7 @@ static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode *
dag_add_material_driver_relations(dag, node, (Material *)n->id); dag_add_material_driver_relations(dag, node, (Material *)n->id);
} }
else if (n->type == NODE_GROUP) { else if (n->type == NODE_GROUP) {
dag_add_material_nodetree_driver_relations(dag, node, (bNodeTree *)n->id); dag_add_shader_nodetree_driver_relations(dag, node, (bNodeTree *)n->id);
} }
} }
} }
@@ -386,18 +387,41 @@ static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Mat
ma->id.flag |= LIB_DOIT; ma->id.flag |= LIB_DOIT;
/* material itself */ /* material itself */
if (ma->adt) { if (ma->adt)
dag_add_driver_relation(ma->adt, dag, node, 1); dag_add_driver_relation(ma->adt, dag, node, 1);
}
/* textures */ /* textures */
// TODO... // TODO...
//dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id); //dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
/* material's nodetree */ /* material's nodetree */
if (ma->nodetree) { if (ma->nodetree)
dag_add_material_nodetree_driver_relations(dag, node, ma->nodetree); dag_add_shader_nodetree_driver_relations(dag, node, ma->nodetree);
} }
/* recursive handling for lamp drivers */
static void dag_add_lamp_driver_relations(DagForest *dag, DagNode *node, Lamp *la)
{
/* Prevent infinite recursion by checking (and tagging the lamp) as having been visited
* already (see build_dag()). This assumes la->id.flag & LIB_DOIT isn't set by anything else
* in the meantime... [#32017]
*/
if (la->id.flag & LIB_DOIT)
return;
else
la->id.flag |= LIB_DOIT;
/* lamp itself */
if (la->adt)
dag_add_driver_relation(la->adt, dag, node, 1);
/* textures */
// TODO...
//dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
/* lamp's nodetree */
if (la->nodetree)
dag_add_shader_nodetree_driver_relations(dag, node, la->nodetree);
} }
static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Object *ob, DagNode *node, int skip_forcefield) static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Object *ob, DagNode *node, int skip_forcefield)
@@ -647,6 +671,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
} }
} }
} }
else if(ob->type == OB_LAMP)
dag_add_lamp_driver_relations(dag, node, ob->data);
/* particles */ /* particles */
psys = ob->particlesystem.first; psys = ob->particlesystem.first;
@@ -817,6 +843,7 @@ DagForest *build_dag(Main *bmain, Scene *sce, short mask)
/* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later [#32017] */ /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later [#32017] */
tag_main_idcode(bmain, ID_MA, FALSE); tag_main_idcode(bmain, ID_MA, FALSE);
tag_main_idcode(bmain, ID_LA, FALSE);
/* add base node for scene. scene is always the first node in DAG */ /* add base node for scene. scene is always the first node in DAG */
scenenode = dag_add_node(dag, sce); scenenode = dag_add_node(dag, sce);

View File

@@ -33,9 +33,12 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
#include "DNA_lamp_types.h" #include "DNA_lamp_types.h"
#include "DNA_material_types.h" #include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h" #include "DNA_texture_types.h"
#include "BLI_listbase.h" #include "BLI_listbase.h"
@@ -232,3 +235,38 @@ void BKE_lamp_free(Lamp *la)
la->id.icon_id = 0; la->id.icon_id = 0;
} }
/* Calculate all drivers for lamps, see material_drivers_update for why this is a bad hack */
static void lamp_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime)
{
bNode *node;
/* nodetree itself */
if (ntree->adt && ntree->adt->drivers.first)
BKE_animsys_evaluate_animdata(scene, &ntree->id, ntree->adt, ctime, ADT_RECALC_DRIVERS);
/* nodes */
for (node = ntree->nodes.first; node; node = node->next)
if (node->id && node->type == NODE_GROUP)
lamp_node_drivers_update(scene, (bNodeTree *)node->id, ctime);
}
void lamp_drivers_update(Scene *scene, Lamp *la, float ctime)
{
/* Prevent infinite recursion by checking (and tagging the lamp) as having been visited already
* (see BKE_scene_update_tagged()). This assumes la->id.flag & LIB_DOIT isn't set by anything else
* in the meantime... [#32017] */
if (la->id.flag & LIB_DOIT)
return;
else
la->id.flag |= LIB_DOIT;
/* lamp itself */
if (la->adt && la->adt->drivers.first)
BKE_animsys_evaluate_animdata(scene, &la->id, la->adt, ctime, ADT_RECALC_DRIVERS);
/* nodes */
if (la->nodetree)
lamp_node_drivers_update(scene, la->nodetree, ctime);
}

View File

@@ -2654,6 +2654,8 @@ void BKE_object_handle_update(Scene *scene, Object *ob)
} }
} }
} }
else if (ob->type == OB_LAMP)
lamp_drivers_update(scene, ob->data, ctime);
/* particles */ /* particles */
if (ob->particlesystem.first) { if (ob->particlesystem.first) {

View File

@@ -1074,6 +1074,7 @@ void BKE_scene_update_tagged(Main *bmain, Scene *scene)
* when trying to find materials with drivers that need evaluating [#32017] * when trying to find materials with drivers that need evaluating [#32017]
*/ */
tag_main_idcode(bmain, ID_MA, FALSE); tag_main_idcode(bmain, ID_MA, FALSE);
tag_main_idcode(bmain, ID_LA, FALSE);
/* update all objects: drivers, matrices, displists, etc. flags set /* update all objects: drivers, matrices, displists, etc. flags set
* by depgraph or manual, no layer check here, gets correct flushed * by depgraph or manual, no layer check here, gets correct flushed
@@ -1143,6 +1144,7 @@ void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
* when trying to find materials with drivers that need evaluating [#32017] * when trying to find materials with drivers that need evaluating [#32017]
*/ */
tag_main_idcode(bmain, ID_MA, FALSE); tag_main_idcode(bmain, ID_MA, FALSE);
tag_main_idcode(bmain, ID_LA, FALSE);
/* BKE_object_handle_update() on all objects, groups and sets */ /* BKE_object_handle_update() on all objects, groups and sets */
scene_update_tagged_recursive(bmain, sce, sce); scene_update_tagged_recursive(bmain, sce, sce);