Depsgraph: Link from material to object shading
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 26 Jan 2017 16:01:37 +0000 (17:01 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 26 Jan 2017 16:01:37 +0000 (17:01 +0100)
This is a ground work for the upcoming changes in Blender 2.8 branch
where we need to do special actions to reconstruct shaders when
material changes.

source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.cc

index 173d5c3221299a5e1c6b2b7ddd912d93cf1fa07c..9d78b99341b766f501881121ef2f83b9d20e0cbd 100644 (file)
@@ -824,11 +824,18 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
        }
 
        /* materials */
-       for (int a = 1; a <= ob->totcol; a++) {
-               Material *ma = give_current_material(ob, a);
-               if (ma != NULL) {
-                       build_material(ma);
+       if (ob->totcol != 0) {
+               for (int a = 1; a <= ob->totcol; a++) {
+                       Material *ma = give_current_material(ob, a);
+                       if (ma != NULL) {
+                               build_material(ma);
+                       }
                }
+               add_operation_node(&ob->id,
+                                  DEPSNODE_TYPE_SHADING,
+                                  DEPSOP_TYPE_EXEC,
+                                  NULL,
+                                  DEG_OPCODE_PLACEHOLDER, "Material Update");
        }
 
        /* geometry collision */
index 82d502dcc1953e991bd96c3e09ad4bb0cec2f0ae..ba7818c21ad02126d33446969159d111d6e85483 100644 (file)
@@ -1418,11 +1418,18 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje
        }
 
        /* materials */
-       if (ob->totcol) {
+       if (ob->totcol != 0) {
+               ComponentKey object_shading_key(&ob->id, DEPSNODE_TYPE_SHADING);
                for (int a = 1; a <= ob->totcol; a++) {
                        Material *ma = give_current_material(ob, a);
                        if (ma != NULL) {
                                build_material(ma);
+                               ComponentKey material_shading_key(&ma->id,
+                                                                 DEPSNODE_TYPE_SHADING);
+                               add_relation(material_shading_key,
+                                            object_shading_key,
+                                            DEPSREL_TYPE_UPDATE,
+                                            "Object Shading");
                        }
                }
        }