[Bf-blender-cvs] [758d7350d64] fracture_modifier: fixes for bind animated mesh: transform and jump issues

Martin Felke noreply at git.blender.org
Sat Jan 13 00:39:27 CET 2018


Commit: 758d7350d6423458d22c10c3dfbbc4368513a035
Author: Martin Felke
Date:   Sat Jan 13 00:39:18 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rB758d7350d6423458d22c10c3dfbbc4368513a035

fixes for bind animated mesh: transform and jump issues

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/modifiers/intern/MOD_remesh.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index bbd72fffe8a..b6bba0d736f 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -3846,7 +3846,7 @@ void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bi
 	MVert *mvert = NULL;
 	MeshIsland *mi, **mi_array;
 	DerivedMesh *dm = NULL;
-	int totvert, count = 0, i = 0;
+	int totvert, count = 0, i = 0, *orig_index;
 	KDTree *tree = NULL;
 	float obquat[4];
 	bool *used;
@@ -3913,6 +3913,7 @@ void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bi
 	quatY = CustomData_get_layer_named(&dm->vertData, CD_PROP_FLT, "quatY");
 	quatZ = CustomData_get_layer_named(&dm->vertData, CD_PROP_FLT, "quatZ");
 	quatW = CustomData_get_layer_named(&dm->vertData, CD_PROP_FLT, "quatW");
+	orig_index = CustomData_get_layer(&dm->vertData, CD_ORIGINDEX);
 
 	//check vertexcount and islandcount, TODO for splitshards... there it might differ, ignore then for now
 	//later do interpolation ? propagate to islands somehow then, not yet now...
@@ -3939,6 +3940,7 @@ void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bi
 
 			n = MEM_mallocN(sizeof(KDTreeNearest) * c, "nearest");
 			copy_v3_v3(co, mvert[i].co);
+			mul_m4_v3(ob->obmat, co);
 			r = BLI_kdtree_find_nearest_n(tree, co, n, c);
 			for (j = 0; j < r; j++)
 			{
@@ -3998,39 +4000,48 @@ void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bi
 				//the 4 rot layers *should* be aligned, caller needs to ensure !
 				bool quats = quatX && quatY && quatZ && quatW;
 				float quat[4] = { 1, 0, 0, 0};
+				int v = fmd->anim_bind[i].v;
 
-
-				if (fmd->anim_bind[i].v >= totvert) {
+				if (v >= totvert) {
 					continue;
 				}
 
-				copy_v3_v3(co, mvert[fmd->anim_bind[i].v].co);
-				//sub_v3_v3v3(orco, co, fmd->anim_bind[i].orco);
-				//sub_v3_v3v3(diff, co, mi->centroid);
+				if (orig_index)
+				{
+					if (orig_index[v] != v  && orig_index[v] != -1)
+					{
+						if (mi->rigidbody->physics_object && mi->rigidbody->type == RBO_TYPE_ACTIVE)
+						{
+							RigidBodyOb* rbo = mi->rigidbody;
 
-				/*if (!(compare_v3v3(diff, orco, 0.1f)))
-				{	//did the index shuffle ? might be if there is a sudden increase in distance
-					mi->rigidbody->flag &= ~RBO_FLAG_KINEMATIC;
-					mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
-					continue;
-				}*/
+							mi->rigidbody->flag &= ~RBO_FLAG_KINEMATIC;
+							mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
+
+							RB_body_set_mass(rbo->physics_object, rbo->mass);
+							RB_body_set_kinematic_state(rbo->physics_object, false);
+							RB_body_activate(rbo->physics_object);
+							continue;
+						}
+					}
+				}
 
+				copy_v3_v3(co, mvert[v].co);
 				sub_v3_v3(co, fmd->anim_bind[i].offset);
 				mul_m4_v3(ob->obmat, co);
 				copy_v3_v3(mi->rigidbody->pos, co);
 
 				if (quats)
 				{
-					quat[0] = quatX[fmd->anim_bind[i].v];
-					quat[1] = quatY[fmd->anim_bind[i].v];
-					quat[2] = quatZ[fmd->anim_bind[i].v];
-					quat[3] = quatW[fmd->anim_bind[i].v];
+					quat[0] = quatX[v];
+					quat[1] = quatY[v];
+					quat[2] = quatZ[v];
+					quat[3] = quatW[v];
 
 					copy_qt_qt(mi->rigidbody->orn, quat);
 				}
 				else {
 					float no[3], vec[3] = {0, 0, 1}, quat[4];
-					normal_short_to_float_v3(no, mvert[fmd->anim_bind[i].v].no);
+					normal_short_to_float_v3(no, mvert[v].no);
 					rotation_between_vecs_to_quat(quat, vec, no);
 					mul_qt_qtqt(quat, obquat, quat);
 					copy_qt_qt(mi->rigidbody->orn, quat);
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index e41b52c7cb0..2d50b7d0687 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -156,7 +156,8 @@ static void dualcon_add_quad(void *output_v, const int vert_indices[4])
 }
 
 static int get_particle_data(RemeshModifierData *rmd, ParticleSystem *psys, Object *ob,
-                             float (**pos)[3], float **size, float (**vel)[3], float(**rot)[4], MemArena *pardata)
+                             float (**pos)[3], float **size, float (**vel)[3], float(**rot)[4],
+                             int **index, MemArena *pardata)
 {
 	//take alive, for now
 	ParticleData *pa;
@@ -168,6 +169,7 @@ static int get_particle_data(RemeshModifierData *rmd, ParticleSystem *psys, Obje
 	(*size) = BLI_memarena_calloc(pardata, sizeof(float) * psys->totpart);
 	(*vel) = BLI_memarena_calloc(pardata, sizeof(float) * 3 * psys->totpart);
 	(*rot) = BLI_memarena_calloc(pardata, sizeof(float) * 4 * psys->totpart);
+	(*index) = BLI_memarena_calloc(pardata, sizeof(int) * psys->totpart);
 
 	for (i = 0; i < psys->totpart; i++)
 	{
@@ -182,6 +184,7 @@ static int get_particle_data(RemeshModifierData *rmd, ParticleSystem *psys, Obje
 		(*size)[j] = pa->size;
 		copy_v3_v3((*vel)[j], pa->state.vel);
 		copy_qt_qt((*rot)[j], pa->state.rot);
+		(*index)[j] = i;
 		j++;
 	}
 
@@ -230,7 +233,7 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 	float (*pos)[3] = NULL, (*vel)[3] = NULL, (*rot)[4] = NULL;
 	float *size = NULL, *psize = NULL, *velX = NULL, *velY = NULL, *velZ = NULL,
 	      *quatX = NULL, *quatY = NULL, *quatZ = NULL, *quatW = NULL;
-	int i = 0, n = 0;
+	int i = 0, n = 0, *index, *orig_index;
 	bool override_size = rmd->pflag & eRemeshFlag_Size;
 	bool verts_only = rmd->pflag & eRemeshFlag_Verts;
 
@@ -243,7 +246,7 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 
 		pardata = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "pardata");
 
-		n = get_particle_data(rmd, psys, ob, &pos, &size, &vel, &rot, pardata);
+		n = get_particle_data(rmd, psys, ob, &pos, &size, &vel, &rot, &index, pardata);
 		dm = CDDM_new(n, 0, 0, 0, 0);
 		mv = dm->getVertArray(dm);
 		psize = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n, "psize");
@@ -256,6 +259,9 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 		quatZ = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n, "quatZ");
 		quatW = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n, "quatW");
 
+		orig_index = CustomData_add_layer(&dm->vertData, CD_ORIGINDEX, CD_CALLOC, NULL, n);
+
+
 #pragma omp parallel for
 		for (i = 0; i < n; i++)
 		{
@@ -269,6 +275,8 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 			quatY[i] = rot[i][1];
 			quatZ[i] = rot[i][2];
 			quatW[i] = rot[i][3];
+
+			orig_index[i] = index[i];
 		}
 
 		if (verts_only)
@@ -300,7 +308,7 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 		MemArena *pardata = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "pardata");
 
 		if (psys)
-			n = get_particle_data(rmd, psys, ob, &pos, &size, &vel, &rot, pardata);
+			n = get_particle_data(rmd, psys, ob, &pos, &size, &vel, &rot, &index, pardata);
 
 		dm = CDDM_new(n + derived->numVertData, 0, 0, 0, 0);
 		psize = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n + derived->numVertData, "psize");
@@ -308,10 +316,12 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 		velY = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n + derived->numVertData, "velY");
 		velZ = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n + derived->numVertData, "velZ");
 
-		quatX = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n, "quatX");
-		quatY = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n, "quatY");
-		quatZ = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n, "quatZ");
-		quatW = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n, "quatW");
+		quatX = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n + derived->numVertData, "quatX");
+		quatY = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n + derived->numVertData, "quatY");
+		quatZ = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n + derived->numVertData, "quatZ");
+		quatW = CustomData_add_layer_named(&dm->vertData, CD_PROP_FLT, CD_CALLOC, NULL, n + derived->numVertData, "quatW");
+
+		orig_index = CustomData_add_layer(&dm->vertData, CD_ORIGINDEX, CD_CALLOC, NULL, n + derived->numVertData);
 
 		mv = dm->getVertArray(dm);
 		mv2 = derived->getVertArray(derived);
@@ -325,6 +335,7 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 		oqZ = CustomData_get_layer_named(&derived->vertData, CD_PROP_FLT, "quatZ");
 		oqW = CustomData_get_layer_named(&derived->vertData, CD_PROP_FLT, "quatW");
 
+
 #pragma omp parallel for
 		for (i = 0; i < n; i++)
 		{
@@ -338,6 +349,8 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 			quatY[i] = rot[i][1];
 			quatZ[i] = rot[i][2];
 			quatW[i] = rot[i][3];
+
+			orig_index[i] = index[i];
 		}
 
 #pragma omp parallel for
@@ -350,9 +363,11 @@ static DerivedMesh *repolygonize(RemeshModifierData *rmd, Object* ob, DerivedMes
 			velZ[i] = ovZ ? ovZ[i-n] : 0.0f;
 
 			quatX[i] = oqX ? oqX[i-n] : 1.0f;
-			quatZ[i] = oqY ? oqY[i-n] : 1.0f;
-			quatY[i] = oqZ ? oqZ[i-n] : 1.0f;
-			quatW[i] = oqW ? oqW[i-n] : 1.0f;
+			quatZ[i] = oqY ? oqY[i-n] : 0.0f;
+			quatY[i] = oqZ ? oqZ[i-n] : 0.0f;
+			quatW[i] = oqW ? oqW[i-n] : 0.0f;
+
+			orig_index[i] = i;
 		}
 
 		if (verts_only)



More information about the Bf-blender-cvs mailing list