[Bf-blender-cvs] [a5ca6d752e3] temp-dynamic-overrides: Hacky code just to try RNA_struct_dynamic_override_apply

Dalai Felinto noreply at git.blender.org
Fri May 25 21:02:41 CEST 2018


Commit: a5ca6d752e34db889aa550dc61af159ce7ece5dd
Author: Dalai Felinto
Date:   Fri May 25 20:58:59 2018 +0200
Branches: temp-dynamic-overrides
https://developer.blender.org/rBa5ca6d752e34db889aa550dc61af159ce7ece5dd

Hacky code just to try RNA_struct_dynamic_override_apply

It is crashing now, I tried either adding a scene setting (EEVEE AO), or
object settings (ob.color).

This also shows a few problems:
* We can't simply tag Scene to update when changing an override set, we need
  the tagging to flush down to the scene objects.

* For scene settings we may want to do at this moment in COW evaluation, however
  for objects the implementation is a bit more tricky. Because we need to change
  the data owned by the object as well. For example, the material.

* In this case it is almost as if we want a cow-cow ID (the OVERRIDEN id should be
  shared by all the objects that are being overridden.

* Also the affected collections thing is to be handled somehow.

===================================================================

M	source/blender/blenkernel/BKE_layer.h
M	source/blender/blenkernel/intern/layer.c
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index 813f737e582..e73f8a5d810 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -141,6 +141,11 @@ bool BKE_view_layer_override_property_remove(
         struct OverrideSet *override_set,
         struct DynamicOverrideProperty *dyn_prop);
 
+
+void BKE_dynamic_override_apply(
+        const struct Depsgraph *depsgraph,
+        ID *id);
+
 /* evaluation */
 
 void BKE_layer_eval_view_layer(
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index b5a350a6234..68333ec6b36 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1220,6 +1220,62 @@ bool BKE_view_layer_override_property_remove(
 	return true;
 }
 
+void BKE_dynamic_override_apply(const struct Depsgraph *depsgraph, ID *id)
+{
+	const ID_Type id_type = GS(id->name);
+	if (ELEM(id_type, ID_SCE, ID_OB) == false) {
+		return;
+	}
+
+	ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+	for (OverrideSet *override_set = view_layer->override_sets.first;
+	     override_set != NULL;
+	     override_set = override_set->next)
+	{
+		if ((override_set->flag & DYN_OVERRIDE_SET_USE) == 0) {
+			continue;
+		}
+
+		if (id_type == ID_SCE) {
+#if 1
+			/** Apply all the scene properties. */
+			for (DynamicOverrideProperty *dyn_prop = override_set->scene_properties.first;
+				 dyn_prop != NULL;
+				 dyn_prop = dyn_prop->next)
+			{
+				if ((dyn_prop->flag & DYN_OVERRIDE_PROP_USE) == 0) {
+					continue;
+				}
+
+				PointerRNA ptr;
+				RNA_id_pointer_create(id, &ptr);
+				RNA_struct_dynamic_override_apply(&ptr, dyn_prop);
+			}
+#endif
+		}
+		else {
+#if 1
+			/** Check if object is in one of the affected collections.
+			 *  If it is, apply all the overrides for the object and its material, mesh, ...
+			 **/
+			for (DynamicOverrideProperty *dyn_prop = override_set->collection_properties.first;
+				 dyn_prop != NULL;
+				 dyn_prop = dyn_prop->next)
+			{
+				if ((dyn_prop->flag & DYN_OVERRIDE_PROP_USE) == 0) {
+					continue;
+				}
+
+				/* If object is in collection ... */
+				PointerRNA ptr;
+				RNA_id_pointer_create(id, &ptr);
+				RNA_struct_dynamic_override_apply(&ptr, dyn_prop);
+			}
+#endif
+		}
+	}
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
index 376e87b38a6..20c231cb829 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -786,6 +786,9 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
 		}
 		object->base_flag = base_flag;
 	}
+
+	const ::Depsgraph *graph = reinterpret_cast<const ::Depsgraph *>(depsgraph);
+	BKE_dynamic_override_apply(graph, id_cow);
 	return id_cow;
 }



More information about the Bf-blender-cvs mailing list