[Bf-blender-cvs] [39ab4da] alembic: Take transformation into account between the duplicator and strands object.

Lukas Tönne noreply at git.blender.org
Tue May 5 15:38:56 CEST 2015


Commit: 39ab4dab664616c42c98bb41e583846116582b1c
Author: Lukas Tönne
Date:   Tue May 5 15:37:00 2015 +0200
Branches: alembic
https://developer.blender.org/rB39ab4dab664616c42c98bb41e583846116582b1c

Take transformation into account between the duplicator and strands
object.

The strand edit mode uses the local space of the active object, which
is the duplicator (and dupli cache owner). The strands data is in local
space of the original particle system object however, so have to
convert. This is a very hackish solution, using the first instance of
the strands data, which only works for single instance data.

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

M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/BKE_editstrands.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/editstrands.c
M	source/blender/bmesh/intern/bmesh_strands_conv.c
M	source/blender/bmesh/intern/bmesh_strands_conv.h
M	source/blender/editors/hair/hair_object_cachelib.c

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

diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 6c27fe6..e0e6189 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -177,7 +177,8 @@ bool BKE_cache_modifier_find_object(struct DupliCache *dupcache, struct Object *
 bool BKE_cache_modifier_find_strands(struct DupliCache *dupcache, struct Object *ob, int hair_system, struct DupliObjectData **r_data, struct Strands **r_strands, const char **r_name);
 
 struct KeyBlock *BKE_cache_modifier_strands_key_insert_key(struct StrandsKeyCacheModifier *md, struct Strands *strands, const char *name, const bool from_mix);
-bool BKE_cache_modifier_strands_key_get(struct Object *ob, struct StrandsKeyCacheModifier **r_skmd, struct DerivedMesh **r_dm, struct Strands **r_strands, struct DupliObjectData **r_dobdata, const char **r_name);
+bool BKE_cache_modifier_strands_key_get(struct Object *ob, struct StrandsKeyCacheModifier **r_skmd, struct DerivedMesh **r_dm, struct Strands **r_strands,
+                                        struct DupliObjectData **r_dobdata, const char **r_name, float r_mat[4][4]);
 
 /* ========================================================================= */
 
diff --git a/source/blender/blenkernel/BKE_editstrands.h b/source/blender/blenkernel/BKE_editstrands.h
index 0638e79..b617042 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -93,8 +93,8 @@ void BKE_editstrands_ensure(struct BMEditStrands *es);
 
 /* === cache shape key conversion === */
 
-struct BMesh *BKE_cache_strands_to_bmesh(struct Strands *strands, struct Key *key, int act_key_nr, struct DerivedMesh *dm);
-struct Strands *BKE_cache_strands_from_bmesh(struct BMEditStrands *edit, struct Key *key, struct DerivedMesh *dm);
+struct BMesh *BKE_cache_strands_to_bmesh(struct Strands *strands, struct Key *key, float mat[4][4], int act_key_nr, struct DerivedMesh *dm);
+struct Strands *BKE_cache_strands_from_bmesh(struct BMEditStrands *edit, struct Key *key, float mat[4][4], struct DerivedMesh *dm);
 
 /* === particle conversion === */
 
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 6fff160..74bdb02 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -1329,7 +1329,7 @@ KeyBlock *BKE_cache_modifier_strands_key_insert_key(StrandsKeyCacheModifier *skm
 	return kb;
 }
 
-bool BKE_cache_modifier_strands_key_get(Object *ob, StrandsKeyCacheModifier **r_skmd, DerivedMesh **r_dm, Strands **r_strands, DupliObjectData **r_dobdata, const char **r_name)
+bool BKE_cache_modifier_strands_key_get(Object *ob, StrandsKeyCacheModifier **r_skmd, DerivedMesh **r_dm, Strands **r_strands, DupliObjectData **r_dobdata, const char **r_name, float r_mat[4][4])
 {
 	CacheLibrary *cachelib = ob->cache_library;
 	CacheModifier *md;
@@ -1350,6 +1350,29 @@ bool BKE_cache_modifier_strands_key_get(Object *ob, StrandsKeyCacheModifier **r_
 				if (r_skmd) *r_skmd = skmd;
 				if (r_dm) *r_dm = dobdata->dm;
 				if (r_dobdata) *r_dobdata = dobdata;
+				
+				/* relative transform from the original hair object to the duplicator local space */
+				/* XXX bad hack, common problem: we want to display strand edit data in the place of "the" instance,
+				 * but in fact there can be multiple instances of the same dupli object data, so this is ambiguous ...
+				 * For our basic use case, just pick the first dupli instance, assuming that it's the only one.
+				 * ugh ...
+				 */
+				if (r_mat) {
+					DupliObject *dob;
+					for (dob = ob->dup_cache->duplilist.first; dob; dob = dob->next) {
+						if (dob->ob == skmd->object)
+							break;
+					}
+					if (dob) {
+						/* note: plain duplis from the dupli cache list are relative
+						 * to the duplicator already! (not in world space like final duplis)
+						 */
+						copy_m4_m4(r_mat, dob->mat);
+					}
+					else
+						unit_m4(r_mat);
+				}
+				
 				return true;
 			}
 		}
diff --git a/source/blender/blenkernel/intern/editstrands.c b/source/blender/blenkernel/intern/editstrands.c
index 741af51..d2ba324 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -89,7 +89,7 @@ BMEditStrands *BKE_editstrands_from_object(Object *ob)
 	
 	{
 		StrandsKeyCacheModifier *skmd;
-		if (BKE_cache_modifier_strands_key_get(ob, &skmd, NULL, NULL, NULL, NULL)) {
+		if (BKE_cache_modifier_strands_key_get(ob, &skmd, NULL, NULL, NULL, NULL, NULL)) {
 			if (skmd->edit)
 				return skmd->edit;
 		}
@@ -176,7 +176,7 @@ void BKE_editstrands_ensure(BMEditStrands *es)
 
 /* === cache shape key conversion === */
 
-BMesh *BKE_cache_strands_to_bmesh(struct Strands *strands, struct Key *key, int act_key_nr, DerivedMesh *dm)
+BMesh *BKE_cache_strands_to_bmesh(struct Strands *strands, struct Key *key, float mat[4][4], int act_key_nr, DerivedMesh *dm)
 {
 	const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_STRANDS(strands);
 	BMesh *bm;
@@ -184,13 +184,13 @@ BMesh *BKE_cache_strands_to_bmesh(struct Strands *strands, struct Key *key, int
 	DM_ensure_tessface(dm);
 	
 	bm = BM_mesh_create(&allocsize);
-	BM_strands_bm_from_strands(bm, strands, key, dm, true, act_key_nr);
+	BM_strands_bm_from_strands(bm, strands, key, dm, mat, true, act_key_nr);
 	editstrands_calc_segment_lengths(bm);
 	
 	return bm;
 }
 
-struct Strands *BKE_cache_strands_from_bmesh(BMEditStrands *edit, struct Key *key, DerivedMesh *dm)
+struct Strands *BKE_cache_strands_from_bmesh(BMEditStrands *edit, struct Key *key, float mat[4][4], DerivedMesh *dm)
 {
 	BMesh *bm = edit ? edit->bm : NULL;
 	Strands *strands = NULL;
@@ -202,7 +202,7 @@ struct Strands *BKE_cache_strands_from_bmesh(BMEditStrands *edit, struct Key *ke
 		
 		bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6);
 		
-		strands = BM_strands_bm_to_strands(bm, strands, key, dm, &bvhtree);
+		strands = BM_strands_bm_to_strands(bm, strands, key, mat, dm, &bvhtree);
 		
 		free_bvhtree_from_mesh(&bvhtree);
 	}
diff --git a/source/blender/bmesh/intern/bmesh_strands_conv.c b/source/blender/bmesh/intern/bmesh_strands_conv.c
index 821c372..43b840b 100644
--- a/source/blender/bmesh/intern/bmesh_strands_conv.c
+++ b/source/blender/bmesh/intern/bmesh_strands_conv.c
@@ -232,9 +232,11 @@ static void bm_make_strands(BMesh *bm, Strands *strands, Key *key, struct Derive
 /**
  * \brief ParticleSystem -> BMesh
  */
-void BM_strands_bm_from_strands(BMesh *bm, Strands *strands, Key *key, struct DerivedMesh *emitter_dm,
+void BM_strands_bm_from_strands(BMesh *bm, Strands *strands, Key *key, struct DerivedMesh *emitter_dm, float mat[4][4],
                             const bool set_key, int act_key_nr)
 {
+	BMIter iter;
+	BMVert *v;
 	KeyBlock *actkey;
 	float (*keyco)[3] = NULL;
 	int totvert, totedge;
@@ -274,6 +276,11 @@ void BM_strands_bm_from_strands(BMesh *bm, Strands *strands, Key *key, struct De
 
 	bm_make_strands(bm, strands, key, emitter_dm, set_key ? keyco : NULL, cd_shape_keyindex_offset);
 
+	/* transform to duplicator local space */
+	BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
+		mul_m4_v3(mat, v->co);
+	}
+
 #if 0 /* TODO */
 	if (me->mselect && me->totselect != 0) {
 
@@ -447,7 +454,7 @@ static void strands_make_strand(BMesh *bm, BMVert *root, Strands *UNUSED(strands
 	}
 }
 
-Strands *BM_strands_bm_to_strands(BMesh *bm, Strands *strands, Key *key, struct DerivedMesh *emitter_dm, struct BVHTreeFromMesh *emitter_bvhtree)
+Strands *BM_strands_bm_to_strands(BMesh *bm, Strands *strands, Key *key, float mat[4][4], struct DerivedMesh *emitter_dm, struct BVHTreeFromMesh *emitter_bvhtree)
 {
 	Strands *oldstrands;
 	int ntotcurves;
@@ -476,6 +483,17 @@ Strands *BM_strands_bm_to_strands(BMesh *bm, Strands *strands, Key *key, struct
 	}
 	bm->elem_index_dirty &= ~BM_VERT;
 	
+	/* transform from edit space (duplicator local space) back to the original object space */
+	{
+		float imat[4][4];
+		int i;
+		
+		invert_m4_m4(imat, mat);
+		
+		for (i = 0; i < strands->totverts; ++i)
+			mul_m4_v3(imat, strands->verts[i].co);
+	}
+	
 	BKE_strands_ensure_normals(strands);
 
 
diff --git a/source/blender/bmesh/intern/bmesh_strands_conv.h b/source/blender/bmesh/intern/bmesh_strands_conv.h
index 316d041..a1b5949 100644
--- a/source/blender/bmesh/intern/bmesh_strands_conv.h
+++ b/source/blender/bmesh/intern/bmesh_strands_conv.h
@@ -51,8 +51,8 @@ void BM_strands_cd_flag_ensure(struct BMesh *bm, const char cd_flag);
 void BM_strands_cd_flag_apply(struct BMesh *bm, const char cd_flag);
 char BM_strands_cd_flag_from_bmesh(struct BMesh *bm);
 
-void BM_strands_bm_from_strands(struct BMesh *bm, struct Strands *strands, struct Key *key, struct DerivedMesh *emitter_dm, const bool set_key, int act_key_nr);
-struct Strands *BM_strands_bm_to_strands(struct BMesh *bm, struct Strands *strands, struct Key *key, struct DerivedMesh *emitter_dm, struct BVHTreeFromMesh *emitter_bvhtree);
+void BM_strands_bm_from_strands(struct BMesh *bm, struct Strands *strands, struct Key *key, struct DerivedMesh *emitter_dm, float mat[4][4], const bool set_key, int act_key_nr);
+struct Strands *BM_strands_bm_to_strands(struct BMesh *bm, struct Strands *strands, struct Key *key, float mat[4][4], struct DerivedMesh *emitter_dm, struct BVHTreeFromMesh *emitter_bvhtree);
 
 int BM_strands_count_psys_keys(struct ParticleSystem *psys);
 void BM_strands_bm_from_psys(struct BMesh *bm, struct Object *ob, struct ParticleSystem *psys, struct DerivedMesh *emitter_dm,
diff --git a/source/blender/editors/hair/hair_object_cachelib.c b/source/blender/editors/hair/hair_object_cachelib.c
index a1d4da8..e075083 100644
--- a/source/blender/editors/hair/hair_object_cachelib.c
+++ b/source/blender/editors/hair/hair_object_cachelib.c
@@ -54,7 +54,7 @@
 
 bool ED_hair_object_has_hair_cache_data(Object *ob)
 {
-	return BKE_cache_modifier_strands_key_get(ob, NULL, NULL, NULL, NULL, NULL);
+	return BKE_cache_modifier_strands_key_get(ob, NULL, NULL, NULL, NULL, NULL, NULL);
 }
 
 bool ED_hair_object_init_cache_edit(Object *ob)
@@ -62,12 +62,13 @@ bool ED_hair_object_init_cache_edit(Object *ob)
 	StrandsKeyCach

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list