[Bf-blender-cvs] [0416eda] hair_immediate_fixes: Replace the dynamic root transform in the implicit solver data with a single transform matrix.

Lukas Tönne noreply at git.blender.org
Fri Sep 19 11:20:28 CEST 2014


Commit: 0416edaa6ae27800ac2999d2419206f3f2a6f9e0
Author: Lukas Tönne
Date:   Thu Sep 18 19:42:20 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rB0416edaa6ae27800ac2999d2419206f3f2a6f9e0

Replace the dynamic root transform in the implicit solver data with a
single transform matrix.

Dynamic properties of the transformation are only needed during the
setup phase when they should be read from external data (hair system
roots) and generate fictitious forces on each point.

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

M	source/blender/physics/intern/BPH_mass_spring.cpp
M	source/blender/physics/intern/implicit.h
M	source/blender/physics/intern/implicit_blender.c

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

diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 7f647d7..db37199 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -102,7 +102,7 @@ void BKE_cloth_solver_set_positions(ClothModifierData *clmd)
 	for (i = 0; i < numverts; i++) {
 		ClothHairRoot *root = &cloth_roots[i];
 		
-		BPH_mass_spring_set_root_motion(id, i, root->loc, ZERO, root->rot, ZERO);
+		BPH_mass_spring_set_rest_transform(id, i, root->rot);
 		BPH_mass_spring_set_motion_state(id, i, verts[i].x, verts[i].v);
 	}
 }
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 7205b60..3743152 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -100,7 +100,7 @@ BLI_INLINE int hash_collpair(int type, CollPair *collpair)
 }
 /* ================ */
 
-void BPH_mass_spring_set_root_motion(struct Implicit_Data *data, int index, const float loc[3], const float vel[3], float rot[3][3], const float angvel[3]);
+void BPH_mass_spring_set_rest_transform(struct Implicit_Data *data, int index, float rot[3][3]);
 
 void BPH_mass_spring_set_motion_state(struct Implicit_Data *data, int index, const float x[3], const float v[3]);
 void BPH_mass_spring_set_position(struct Implicit_Data *data, int index, const float x[3]);
@@ -121,7 +121,7 @@ void BPH_mass_spring_apply_result(struct Implicit_Data *data);
 /* Clear the force vector at the beginning of the time step */
 void BPH_mass_spring_force_clear(struct Implicit_Data *data);
 /* Fictitious forces introduced by moving coordinate systems */
-void BPH_mass_spring_force_reference_frame(struct Implicit_Data *data, int index);
+void BPH_mass_spring_force_reference_frame(struct Implicit_Data *data, int index, const float acceleration[3], const float omega[3], const float domega_dt[3]);
 /* Simple uniform gravity force */
 void BPH_mass_spring_force_gravity(struct Implicit_Data *data, const float g[3]);
 /* Global drag force (velocity damping) */
diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c
index 0cf368c..26604e1 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -811,24 +811,14 @@ DO_INLINE void subadd_bfmatrixS_bfmatrixS( fmatrix3x3 *to, fmatrix3x3 *from, flo
 ///////////////////////////////////////////////////////////////////
 // simulator start
 ///////////////////////////////////////////////////////////////////
-typedef struct RootTransform {
-	float loc[3];		/* translation in world space */
-	float rot[3][3];	/* rotation from root to world space */
-	
-	float vel[3];		/* velocity in root space */
-	float omega[3];		/* angular velocity in root space */
-	
-	float acc[3];		/* acceleration in root space */
-	float domega_dt[3];	/* angular acceleration in root space */
-} RootTransform;
 
 typedef struct Implicit_Data  {
 	/* inputs */
 	fmatrix3x3 *bigI;			/* identity (constant) */
+	fmatrix3x3 *tfm;			/* local coordinate transform */
 	fmatrix3x3 *M;				/* masses */
 	lfVector *F;				/* forces */
 	fmatrix3x3 *dFdV, *dFdX;	/* force jacobians */
-	RootTransform *root;		/* root transforms */
 	
 	/* motion state data */
 	lfVector *X, *Xnew;			/* positions */
@@ -849,6 +839,7 @@ Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings)
 	Implicit_Data *id = (Implicit_Data *)MEM_callocN(sizeof(Implicit_Data), "implicit vecmat");
 	
 	/* process diagonal elements */
+	id->tfm = create_bfmatrix(numverts, 0);
 	id->A = create_bfmatrix(numverts, numsprings);
 	id->dFdV = create_bfmatrix(numverts, numsprings);
 	id->dFdX = create_bfmatrix(numverts, numsprings);
@@ -866,8 +857,6 @@ Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings)
 	id->dV = create_lfvector(numverts);
 	id->z = create_lfvector(numverts);
 
-	id->root = MEM_callocN(sizeof(RootTransform) * numverts, "root transforms");
-
 	initdiag_bfmatrix(id->bigI, I);
 
 	return id;
@@ -875,6 +864,7 @@ Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings)
 
 void BPH_mass_spring_solver_free(Implicit_Data *id)
 {
+	del_bfmatrix(id->tfm);
 	del_bfmatrix(id->A);
 	del_bfmatrix(id->dFdV);
 	del_bfmatrix(id->dFdX);
@@ -893,53 +883,33 @@ void BPH_mass_spring_solver_free(Implicit_Data *id)
 	del_lfvector(id->dV);
 	del_lfvector(id->z);
 	
-	MEM_freeN(id->root);
-	
 	MEM_freeN(id);
 }
 
 /* ==== Transformation from/to root reference frames ==== */
 
-BLI_INLINE void point_world_to_root(Implicit_Data *data, int index, float r[3], const float v[3])
-{
-	RootTransform *root = &data->root[index];
-	sub_v3_v3v3(r, v, root->loc);
-	mul_transposed_m3_v3(root->rot, r);
-}
-
-BLI_INLINE void point_root_to_world(Implicit_Data *data, int index, float r[3], const float v[3])
+BLI_INLINE void world_to_root_v3(Implicit_Data *data, int index, float r[3], const float v[3])
 {
-	RootTransform *root = &data->root[index];
-	mul_v3_m3v3(r, root->rot, v);
-	add_v3_v3(r, root->loc);
-}
-
-BLI_INLINE void direction_world_to_root(Implicit_Data *data, int index, float r[3], const float v[3])
-{
-	RootTransform *root = &data->root[index];
 	copy_v3_v3(r, v);
-	mul_transposed_m3_v3(root->rot, r);
+	mul_transposed_m3_v3(data->tfm[index].m, r);
 }
 
-BLI_INLINE void direction_root_to_world(Implicit_Data *data, int index, float r[3], const float v[3])
+BLI_INLINE void root_to_world_v3(Implicit_Data *data, int index, float r[3], const float v[3])
 {
-	RootTransform *root = &data->root[index];
-	mul_v3_m3v3(r, root->rot, v);
+	mul_v3_m3v3(r, data->tfm[index].m, v);
 }
 
-BLI_INLINE void matrix_world_to_root(Implicit_Data *data, int index, float r[3][3], float m[3][3])
+BLI_INLINE void world_to_root_m3(Implicit_Data *data, int index, float r[3][3], float m[3][3])
 {
-	RootTransform *root = &data->root[index];
 	float trot[3][3];
-	copy_m3_m3(trot, root->rot);
+	copy_m3_m3(trot, data->tfm[index].m);
 	transpose_m3(trot);
 	mul_m3_m3m3(r, trot, m);
 }
 
-BLI_INLINE void matrix_root_to_world(Implicit_Data *data, int index, float r[3][3], float m[3][3])
+BLI_INLINE void root_to_world_m3(Implicit_Data *data, int index, float r[3][3], float m[3][3])
 {
-	RootTransform *root = &data->root[index];
-	mul_m3_m3m3(r, root->rot, m);
+	mul_m3_m3m3(r, data->tfm[index].m, m);
 }
 
 /* ================================ */
@@ -1332,52 +1302,36 @@ void BPH_mass_spring_apply_result(Implicit_Data *data)
 	cp_lfvector(data->V, data->Vnew, numverts);
 }
 
-void BPH_mass_spring_set_root_motion(Implicit_Data *data, int index, const float loc[3], const float vel[3], float rot[3][3], const float angvel[3])
+void BPH_mass_spring_set_rest_transform(Implicit_Data *data, int index, float tfm[3][3])
 {
-	RootTransform *root = &data->root[index];
-	
 #ifdef CLOTH_ROOT_FRAME
-	copy_v3_v3(root->loc, loc);
-	copy_v3_v3(root->vel, vel);
-	copy_m3_m3(root->rot, rot);
-	copy_v3_v3(root->omega, angvel);
-	/* XXX root frame acceleration ignored for now */
-	zero_v3(root->acc);
-	zero_v3(root->domega_dt);
+	copy_m3_m3(data->tfm[index].m, tfm);
 #else
-	zero_v3(root->loc);
-	zero_v3(root->vel);
-	unit_m3(root->rot);
-	zero_v3(root->omega);
-	zero_v3(root->acc);
-	zero_v3(root->domega_dt);
-	(void)loc;
-	(void)vel;
-	(void)rot;
-	(void)angvel;
+	unit_m3(data->tfm[index].m);
+	(void)tfm;
 #endif
 }
 
 void BPH_mass_spring_set_motion_state(Implicit_Data *data, int index, const float x[3], const float v[3])
 {
-	point_world_to_root(data, index, data->X[index], x);
-	direction_world_to_root(data, index, data->V[index], v);
+	world_to_root_v3(data, index, data->X[index], x);
+	world_to_root_v3(data, index, data->V[index], v);
 }
 
 void BPH_mass_spring_set_position(Implicit_Data *data, int index, const float x[3])
 {
-	point_world_to_root(data, index, data->X[index], x);
+	world_to_root_v3(data, index, data->X[index], x);
 }
 
 void BPH_mass_spring_set_velocity(Implicit_Data *data, int index, const float v[3])
 {
-	direction_world_to_root(data, index, data->V[index], v);
+	world_to_root_v3(data, index, data->V[index], v);
 }
 
 void BPH_mass_spring_get_motion_state(struct Implicit_Data *data, int index, float x[3], float v[3])
 {
-	if (x) point_root_to_world(data, index, x, data->X[index]);
-	if (v) direction_root_to_world(data, index, v, data->V[index]);
+	if (x) root_to_world_v3(data, index, x, data->X[index]);
+	if (v) root_to_world_v3(data, index, v, data->V[index]);
 }
 
 void BPH_mass_spring_set_vertex_mass(Implicit_Data *data, int index, float mass)
@@ -1413,26 +1367,20 @@ void BPH_mass_spring_clear_constraints(Implicit_Data *data)
 
 void BPH_mass_spring_add_constraint_ndof0(Implicit_Data *data, int index, const float dV[3])
 {
-	RootTransform *root = &data->root[index];
-	
 	zero_m3(data->S[index].m);
 	
-	copy_v3_v3(data->z[index], dV);
-	mul_transposed_m3_v3(root->rot, data->z[index]);
+	world_to_root_v3(data, index, data->z[index], dV);
 }
 
 void BPH_mass_spring_add_constraint_ndof1(Implicit_Data *data, int index, const float c1[3], const float c2[3], const float dV[3])
 {
-	RootTransform *root = &data->root[index];
 	float m[3][3], p[3], q[3], u[3], cmat[3][3];
 	
-	copy_v3_v3(p, c1);
-	mul_transposed_m3_v3(root->rot, p);
+	world_to_root_v3(data, index, p, c1);
 	mul_fvectorT_fvector(cmat, p, p);
 	sub_m3_m3m3(m, I, cmat);
 	
-	copy_v3_v3(q, c2);
-	mul_transposed_m3_v3(root->rot, q);
+	world_to_root_v3(data, index, q, c2);
 	mul_fvectorT_fvector(cmat, q, q);
 	sub_m3_m3m3(m, m, cmat);
 	
@@ -1440,26 +1388,22 @@ void BPH_mass_spring_add_constraint_ndof1(Implicit_Data *data, int index, const
 	copy_m3_m3(data->S[index].m, m);
 //	mul_m3_m3m3(data->S[index].m, data->S[index].m, m);
 	
-	copy_v3_v3(u, dV);
-	mul_transposed_m3_v3(root->rot, u);
+	world_to_root_v3(data, index, u, dV);
 	add_v3_v3(data->z[index], u);
 }
 
 void BPH_mass_spring_add_constraint_ndof2(Implicit_Data *data, int index, const float c1[3], const float dV[3])
 {
-	RootTransform *root = &data->root[index];
 	float m[3][3], p[3], u[3], cmat[3][3];
 	
-	copy_v3_v3(p, c1);
-	mul_transposed_m3_v3(root->rot, p);
+	world_to_root_v3(data, index, p, c1);
 	mul_fvectorT_fvector(cmat, p, p);
 	sub_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list