[Bf-blender-cvs] [92598a6] alembic_pointcache: Mesh overrides for duplis from cached Alembic data.

Lukas Tönne noreply at git.blender.org
Mon Mar 16 12:29:14 CET 2015


Commit: 92598a6e229c718f53553a76f9eb03c198298ab5
Author: Lukas Tönne
Date:   Mon Mar 16 12:15:50 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB92598a6e229c718f53553a76f9eb03c198298ab5

Mesh overrides for duplis from cached Alembic data.

If a duplicator has cached data it will now replace the derivedFinal
mesh of objects with the cached version for drawing.

This is a compromise atm: It would be better to actually draw derived
meshes directly, so that we don't have to modify objects. Then we could
also have multiple different instances of the same orignal object
(in whatever way these might be defined). DNA Objects would then be
totally separate from duplis, but at this point the drawing and render
code makes this unfeasible.

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

M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/editors/space_view3d/view3d_draw.c

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 941a4df..3f6ae79 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -82,6 +82,7 @@ void BKE_object_dupli_cache_update(struct Scene *scene, struct Object *ob, struc
 void BKE_object_dupli_cache_clear(struct Object *ob);
 void BKE_object_dupli_cache_free(struct Object *ob);
 bool BKE_object_dupli_cache_contains(struct Object *ob, struct Object *other);
+struct DupliObjectData *BKE_dupli_cache_find_data(struct DupliCache *dupcache, struct Object *ob);
 
 struct DupliObjectData *BKE_dupli_cache_add_mesh(struct DupliCache *dupcache, struct Object *ob, struct DerivedMesh *dm);
 void BKE_dupli_cache_add_instance(struct DupliCache *dupcache, float obmat[4][4], struct DupliObjectData *data);
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index b8695d4..558f810 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1332,8 +1332,14 @@ int count_duplilist(Object *ob)
 
 static void dupli_object_data_free(DupliObjectData *data)
 {
-	if (data->cache_dm)
+	if (data->cache_dm) {
+		/* we lock DMs in the cache to prevent freeing outside,
+		 * now allow releasing again
+		 */
+		data->cache_dm->needsFree = true;
+		
 		data->cache_dm->release(data->cache_dm);
+	}
 	
 	MEM_freeN(data);
 }
@@ -1373,19 +1379,15 @@ static DupliCache *dupli_cache_new(void)
 	return dupcache;
 }
 
-static DupliObjectData *dupli_cache_add_object_data(DupliCache *dupcache)
+static DupliObjectData *dupli_cache_add_object_data(DupliCache *dupcache, Object *ob)
 {
 	DupliObjectData *data = MEM_callocN(sizeof(DupliObjectData), "dupli object data");
 	
-	BLI_ghash_insert(dupcache->ghash, data, data);
+	data->ob = ob;
+	BLI_ghash_insert(dupcache->ghash, data->ob, data);
 	return data;
 }
 
-static bool dupli_cache_contains_object_data(DupliCache *dupcache, DupliObjectData *data)
-{
-	return BLI_ghash_lookup(dupcache->ghash, data) != NULL;
-}
-
 static DupliObject *dupli_cache_add_object(DupliCache *dupcache)
 {
 	DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupli object");
@@ -1396,6 +1398,8 @@ static DupliObject *dupli_cache_add_object(DupliCache *dupcache)
 	return dob;
 }
 
+/* ------------------------------------------------------------------------- */
+
 void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *eval_ctx)
 {
 	const eCacheLibrary_EvalMode eval_mode = eval_ctx->mode == DAG_EVAL_RENDER ? CACHE_LIBRARY_EVAL_RENDER : CACHE_LIBRARY_EVAL_VIEWPORT;
@@ -1455,13 +1459,20 @@ bool BKE_object_dupli_cache_contains(Object *ob, Object *other)
 	return false;
 }
 
+DupliObjectData *BKE_dupli_cache_find_data(DupliCache *dupcache, Object *ob)
+{
+	DupliObjectData *data = BLI_ghash_lookup(dupcache->ghash, ob);
+	return data;
+}
+
 DupliObjectData *BKE_dupli_cache_add_mesh(DupliCache *dupcache, Object *ob, DerivedMesh *dm)
 {
-	DupliObjectData *data = dupli_cache_add_object_data(dupcache);
-	
-	data->ob = ob;
+	DupliObjectData *data = dupli_cache_add_object_data(dupcache, ob);
 	data->cache_dm = dm;
 	
+	/* we own this dm now and need to protect it until we free it ourselves */
+	dm->needsFree = false;
+	
 	return data;
 }
 
@@ -1470,7 +1481,7 @@ void BKE_dupli_cache_add_instance(DupliCache *dupcache, float obmat[4][4], Dupli
 	DupliObject *dob = dupli_cache_add_object(dupcache);
 	
 	/* data must have been created correctly */
-	BLI_assert(dupli_cache_contains_object_data(dupcache, data));
+	BLI_assert(BLI_ghash_lookup(dupcache->ghash, data->ob) != NULL);
 	
 	dob->ob = data->ob;
 	copy_m4_m4(dob->mat, obmat);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 58ef918..6bc5e17 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -55,6 +55,7 @@
 #include "BKE_camera.h"
 #include "BKE_context.h"
 #include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_image.h"
 #include "BKE_key.h"
 #include "BKE_main.h"
@@ -2050,7 +2051,10 @@ static void draw_dupli_objects_color(
 	if (dob) dob_next = dupli_step(dob->next);
 
 	for (; dob; dob_prev = dob, dob = dob_next, dob_next = dob_next ? dupli_step(dob_next->next) : NULL) {
+		DerivedMesh *final_dm; /* for restoring after override */
+
 		tbase.object = dob->ob;
+		final_dm = dob->ob->derivedFinal;
 
 		/* Make sure lod is updated from dupli's position */
 
@@ -2087,6 +2091,13 @@ static void draw_dupli_objects_color(
 			glColor3ubv(color_rgb);
 		}
 		
+		/* override final DM */
+		if (base->object->dup_cache) {
+			DupliObjectData *dob_data = BKE_dupli_cache_find_data(base->object->dup_cache, tbase.object);
+			if (dob_data->cache_dm)
+				tbase.object->derivedFinal = dob_data->cache_dm;
+		}
+		
 		/* generate displist, test for new object */
 		if (dob_prev && dob_prev->ob != dob->ob) {
 			if (use_displist == true)
@@ -2156,6 +2167,7 @@ static void draw_dupli_objects_color(
 		tbase.object->dtx = dtx;
 		tbase.object->transflag = transflag;
 		tbase.object->currentlod = savedlod;
+		tbase.object->derivedFinal = final_dm;
 	}
 
 	if (apply_data) {




More information about the Bf-blender-cvs mailing list