[Bf-blender-cvs] [81615ddf861] blender2.8: Cycles: Fix infinite update when using duplis

Sergey Sharybin noreply at git.blender.org
Tue Jun 6 16:30:20 CEST 2017


Commit: 81615ddf86173e6525fb92d26dc5cf130a4cdef5
Author: Sergey Sharybin
Date:   Tue Jun 6 16:27:02 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB81615ddf86173e6525fb92d26dc5cf130a4cdef5

Cycles: Fix infinite update when using duplis

The issue was caused by usage of address of dupli-object (which will vary
from iteration process to iteration process) as something denoting whether
we've got the data synchronized to Cycles or not.

For now solved by using address of original object (the one DupliObject
points to) as a pointer for the map.

Need to do more thoughts about this.

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_sync.h
M	source/blender/makesrna/intern/rna_depsgraph.c

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 3dfb2b1913d..75933c955ee 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -945,6 +945,7 @@ static void sync_mesh_fluid_motion(BL::Object& b_ob, Scene *scene, Mesh *mesh)
 }
 
 Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
+                             BL::Object& b_ob_instance,
                              bool object_updated,
                              bool hide_tris)
 {
@@ -958,7 +959,7 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
 
 	/* test if we can instance or if the object is modified */
 	BL::ID b_ob_data = b_ob.data();
-	BL::ID key = (BKE_object_is_modified(b_ob))? b_ob: b_ob_data;
+	BL::ID key = (BKE_object_is_modified(b_ob))? b_ob_instance: b_ob_data;
 	BL::Material material_override = render_layer.material_override;
 
 	/* find shader indices */
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index eaf257c0c73..991b834dcfa 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -94,12 +94,13 @@ static uint object_ray_visibility(BL::Object& b_ob)
 void BlenderSync::sync_light(BL::Object& b_parent,
                              int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
                              BL::Object& b_ob,
+                             BL::Object& b_ob_instance,
                              Transform& tfm,
                              bool *use_portal)
 {
 	/* test if we need to sync */
 	Light *light;
-	ObjectKey key(b_parent, persistent_id, b_ob);
+	ObjectKey key(b_parent, persistent_id, b_ob_instance);
 
 	if(!light_map.sync(&light, b_ob, b_parent, key)) {
 		if(light->is_portal)
@@ -243,13 +244,17 @@ Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
                                  BlenderObjectCulling& culling,
                                  bool *use_portal)
 {
+	const bool is_instance = b_dupli_iter->is_instance();
 	BL::Object b_ob = b_dupli_iter->object();
-	BL::Object b_parent = b_dupli_iter->parent() ? b_dupli_iter->parent() : b_dupli_iter->object();
+	BL::Object b_parent = is_instance ? b_dupli_iter->parent()
+	                                  : b_dupli_iter->object();
+	BL::Object b_ob_instance = is_instance ? b_dupli_iter->instance_object()
+	                                       : b_ob;
 	const bool motion = motion_time != 0.0f;
 	/*const*/ Transform tfm = get_transform(b_ob.matrix_world());
 	int *persistent_id = NULL;
 	BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id_array;
-	if(b_dupli_iter->parent()) {
+	if(is_instance) {
 		persistent_id_array = b_dupli_iter->persistent_id();
 		persistent_id = persistent_id_array.data;
 	}
@@ -257,8 +262,16 @@ Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
 	/* light is handled separately */
 	if(object_is_light(b_ob)) {
 		/* don't use lamps for excluded layers used as mask layer */
-		if(!motion && !((layer_flag & render_layer.holdout_layer) && (layer_flag & render_layer.exclude_layer)))
-			sync_light(b_parent, persistent_id, b_ob, tfm, use_portal);
+		if(!motion && !((layer_flag & render_layer.holdout_layer) &&
+		                (layer_flag & render_layer.exclude_layer)))
+		{
+			sync_light(b_parent,
+			           persistent_id,
+			           b_ob,
+			           b_ob_instance,
+			           tfm,
+			           use_portal);
+		}
 
 		return NULL;
 	}
@@ -274,7 +287,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
 	}
 
 	/* key to lookup object */
-	ObjectKey key(b_parent, persistent_id, b_ob);
+	ObjectKey key(b_parent, persistent_id, b_ob_instance);
 	Object *object;
 
 	/* motion vector case */
@@ -316,7 +329,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
 	bool use_holdout = (layer_flag & render_layer.holdout_layer) != 0;
 	
 	/* mesh sync */
-	object->mesh = sync_mesh(b_ob, object_updated, hide_tris);
+	object->mesh = sync_mesh(b_ob, b_ob_instance, object_updated, hide_tris);
 
 	/* special case not tracked by object update flags */
 
@@ -385,7 +398,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph::duplis_iterator& b_dupli_iter,
 		}
 
 		/* dupli texture coordinates and random_id */
-		if(b_dupli_iter->parent()) {
+		if(is_instance) {
 			object->dupli_generated = 0.5f*get_float3(b_dupli_iter->orco()) - make_float3(0.5f, 0.5f, 0.5f);
 			object->dupli_uv = get_float2(b_dupli_iter->uv());
 			object->random_id = b_dupli_iter->random_id();
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 4c8772d4d8f..a9f63346e00 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -115,7 +115,10 @@ private:
 	void sync_curve_settings();
 
 	void sync_nodes(Shader *shader, BL::ShaderNodeTree& b_ntree);
-	Mesh *sync_mesh(BL::Object& b_ob, bool object_updated, bool hide_tris);
+	Mesh *sync_mesh(BL::Object& b_ob,
+	                BL::Object& b_ob_instance,
+	                bool object_updated,
+	                bool hide_tris);
 	void sync_curves(Mesh *mesh,
 	                 BL::Mesh& b_mesh,
 	                 BL::Object& b_ob,
@@ -130,6 +133,7 @@ private:
 	void sync_light(BL::Object& b_parent,
 	                int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
 	                BL::Object& b_ob,
+	                BL::Object& b_ob_instance,
 	                Transform& tfm,
 	                bool *use_portal);
 	void sync_background_light(bool use_portal);
diff --git a/source/blender/makesrna/intern/rna_depsgraph.c b/source/blender/makesrna/intern/rna_depsgraph.c
index c1f84b44447..b995347856b 100644
--- a/source/blender/makesrna/intern/rna_depsgraph.c
+++ b/source/blender/makesrna/intern/rna_depsgraph.c
@@ -59,6 +59,17 @@ static PointerRNA rna_DepsgraphIter_object_get(PointerRNA *ptr)
 	return rna_pointer_inherit_refine(ptr, &RNA_Object, iterator->current);
 }
 
+static PointerRNA rna_DepsgraphIter_instance_object_get(PointerRNA *ptr)
+{
+	BLI_Iterator *iterator = ptr->data;
+	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
+	Object *instance_object = NULL;
+	if (deg_iter->dupli_object_current != NULL) {
+		instance_object = deg_iter->dupli_object_current->ob;
+	}
+	return rna_pointer_inherit_refine(ptr, &RNA_Object, instance_object);
+}
+
 static PointerRNA rna_DepsgraphIter_parent_get(PointerRNA *ptr)
 {
 	BLI_Iterator *iterator = ptr->data;
@@ -101,6 +112,13 @@ static void rna_DepsgraphIter_uv_get(PointerRNA *ptr, float *uv)
 	       sizeof(deg_iter->dupli_object_current->uv));
 }
 
+static int rna_DepsgraphIter_is_instance_get(PointerRNA *ptr)
+{
+	BLI_Iterator *iterator = ptr->data;
+	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
+	return (deg_iter->dupli_object_current != NULL);
+}
+
 /* **************** Depsgraph **************** */
 
 static void rna_Depsgraph_debug_graphviz(Depsgraph *graph, const char *filename)
@@ -224,6 +242,12 @@ static void rna_def_depsgraph_iter(BlenderRNA *brna)
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 	RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_object_get", NULL, NULL, NULL);
 
+	prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_struct_type(prop, "Object");
+	RNA_def_property_ui_text(prop, "Instance Object", "Object which is being instanced by this iterator");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+	RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_instance_object_get", NULL, NULL, NULL);
+
 	prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
 	RNA_def_property_struct_type(prop, "Object");
 	RNA_def_property_ui_text(prop, "Parent", "Parent of the duplication list");
@@ -256,6 +280,11 @@ static void rna_def_depsgraph_iter(BlenderRNA *brna)
 	RNA_def_property_array(prop, 2);
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 	RNA_def_property_float_funcs(prop, "rna_DepsgraphIter_uv_get", NULL, NULL);
+
+	prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Is Instance", "Denotes whether the object is ocming from dupli-list");
+	RNA_def_property_boolean_funcs(prop, "rna_DepsgraphIter_is_instance_get", NULL);
 }
 
 static void rna_def_depsgraph(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list