[Bf-blender-cvs] [77c1b22] hair_system: Merge branch 'hair_immediate_fixes' into hair_system

Lukas Tönne noreply at git.blender.org
Tue Oct 14 13:44:01 CEST 2014


Commit: 77c1b22b6a1ecd963204eb40ede40127d7d397d2
Author: Lukas Tönne
Date:   Tue Oct 14 13:40:36 2014 +0200
Branches: hair_system
https://developer.blender.org/rB77c1b22b6a1ecd963204eb40ede40127d7d397d2

Merge branch 'hair_immediate_fixes' into hair_system

Conflicts:
	release/datafiles/locale
	release/scripts/addons
	source/blender/physics/intern/BPH_mass_spring.cpp

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



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

diff --cc source/blender/physics/BPH_mass_spring.h
index 8db6433,10f05fc..e5eea0f
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@@ -56,18 -49,8 +57,18 @@@ int BPH_mass_spring_solver_numvert(stru
  int BPH_cloth_solver_init(struct Object *ob, struct ClothModifierData *clmd);
  void BPH_cloth_solver_free(struct ClothModifierData *clmd);
  int BPH_cloth_solve(struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors);
- void BKE_cloth_solver_set_positions(struct ClothModifierData *clmd);
+ void BPH_cloth_solver_set_positions(struct ClothModifierData *clmd);
  
 +struct HairSolverData *BPH_hair_solver_create(struct Object *ob, struct HairSystem *hsys);
 +void BPH_hair_solver_free(struct HairSolverData *data);
 +
 +void BPH_hair_solver_set_externals(struct HairSolverData *data, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, struct EffectorWeights *effector_weights);
 +void BPH_hair_solver_clear_externals(struct HairSolverData *data);
 +
 +void BPH_hair_solver_set_positions(struct HairSolverData *data, struct Object *ob, struct HairSystem *hsys);
 +void BPH_hair_solve(struct HairSolverData *data, struct Object *ob, struct HairSystem *hsys, float time, float timestep, struct SimDebugData *debug_data);
 +void BPH_hair_solver_apply_positions(struct HairSolverData *data, struct Scene *scene, struct Object *ob, struct HairSystem *hsys);
 +
  bool implicit_hair_volume_get_texture_data(struct Object *UNUSED(ob), struct ClothModifierData *clmd, struct ListBase *UNUSED(effectors), struct VoxelData *vd);
  
  #ifdef __cplusplus
diff --cc source/blender/physics/intern/BPH_mass_spring.cpp
index 96604b8,875b7bf..6a68676
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@@ -53,8 -51,51 +53,53 @@@ extern "C" 
  #include "BPH_mass_spring.h"
  #include "implicit.h"
  
 +/* ======== Cloth Solver ======== */
 +
+ BLI_INLINE bool exclude_vertex(Cloth *cloth, int index)
+ {
+ 	return cloth->verts[index].flags & CLOTH_VERT_FLAG_EXCLUDE;
+ }
+ 
+ BLI_INLINE bool exclude_spring(Cloth *cloth, ClothSpring *spring)
+ {
+ 	switch (spring->type) {
+ 		case CLOTH_SPRING_TYPE_BENDING_ANG:
+ 			return exclude_vertex(cloth, spring->ij) || exclude_vertex(cloth, spring->kl) || exclude_vertex(cloth, spring->mn);
+ 			
+ 		default:
+ 			return exclude_vertex(cloth, spring->ij) || exclude_vertex(cloth, spring->kl);
+ 	}
+ }
+ 
+ /* Assign a running index to each cloth vertex for mapping to solver data,
+  * or -1 if the vertex is to be ignored.
+  * Returns the number of solver vertices required.
+  */
+ static int assign_solver_indices(Cloth *cloth)
+ {
+ 	ClothVertex *vert;
+ 	int i, si;
+ 	
+ 	si = 0;
+ 	vert = cloth->verts;
+ 	for (i = 0; i < cloth->numverts; ++i, ++vert) {
+ 		if (exclude_vertex(cloth, i))
+ 			vert->solver_index = -1;
+ 		else {
+ 			vert->solver_index = si;
+ 			++si;
+ 		}
+ 	}
+ 	
+ 	/* first element of solver data matrices is used to store numbers ...
+ 	 * have to keep at least one
+ 	 */
+ 	if (si == 0)
+ 		si = 1;
+ 	
+ 	return si;
+ }
+ 
  /* Number of off-diagonal non-zero matrix blocks.
   * Basically there is one of these for each vertex-vertex interaction.
   */
@@@ -728,436 -870,3 +874,446 @@@ int BPH_cloth_solve(Object *ob, float f
  	
  	return 1;
  }
 +
 +/* ======== Hair Solver ======== */
 +
 +struct HairSolverData {
 +	Implicit_Data *id; /* internal solver data */
 +	
 +	/* externals (updated for every step) */
 +	Scene *scene;
 +	ListBase *effectors;
 +};
 +
 +static void hair_solver_count(HairSystem *hsys, int *r_totverts, int *r_totsprings)
 +{
 +	int i;
 +	int totverts = 0, totsprings = 0;
 +	
 +	HairCurve *curve = hsys->curves;
 +	for (i = 0; i < hsys->totcurves; ++i, ++curve) {
 +		totverts += curve->totpoints;
 +		
 +		if (curve->totpoints > 1) {
 +			/* for each segment, add
 +			 *   + 1 spring for stretch
 +			 *   + 3 springs for bend
 +			 *   + 1 spring for goals
 +			 */
 +			totsprings += (curve->totpoints-1) * (1 + 3 + 1);
 +		}
 +	}
 +	
 +	*r_totverts = totverts;
 +	*r_totsprings = totsprings;
 +}
 +
 +HairSolverData *BPH_hair_solver_create(Object *UNUSED(ob), HairSystem *hsys)
 +{
 +	HairSolverData *data = (HairSolverData *)MEM_callocN(sizeof(HairSolverData), "hair solver data");
 +	int totverts, totsprings;
 +	
 +	hair_solver_count(hsys, &totverts, &totsprings);
 +	data->id = BPH_mass_spring_solver_create(totverts, totsprings);
 +	
 +	int ktot = 0;
 +	HairCurve *curve = hsys->curves;
 +	for (int i = 0; i < hsys->totcurves; ++i, ++curve) {
 +		HairPoint *point = curve->points;
 +		for (int k = 0; k < curve->totpoints; ++k, ++ktot, ++point) {
 +			/* XXX is individual hair point mass needed? */
 +			BPH_mass_spring_set_vertex_mass(data->id, ktot, 1.0f);
 +		}
 +	}
 +	
 +	return data;
 +}
 +
 +void BPH_hair_solver_free(HairSolverData *data)
 +{
 +	if (data) {
 +		if (data->id)
 +			BPH_mass_spring_solver_free(data->id);
 +		MEM_freeN(data);
 +	}
 +}
 +
 +void BPH_hair_solver_set_externals(HairSolverData *data, Scene *scene, Object *ob, DerivedMesh *dm, EffectorWeights *effector_weights)
 +{
 +	data->scene = scene;
 +	data->effectors = pdInitEffectors(scene, ob, NULL, effector_weights, true);
 +}
 +
 +void BPH_hair_solver_clear_externals(HairSolverData *data)
 +{
 +	data->scene = NULL;
 +	pdEndEffectors(&data->effectors);
 +}
 +
 +void BPH_hair_solver_set_positions(HairSolverData *data, Object *ob, HairSystem *hsys)
 +{
 +	float obmat[4][4];
 +	copy_m4_m4(obmat, ob->obmat);
 +	
 +	int ktot = 0;
 +	HairCurve *curve = hsys->curves;
 +	for (int i = 0; i < hsys->totcurves; ++i, ++curve) {
 +		HairPoint *point = curve->points;
 +		for (int k = 0; k < curve->totpoints; ++k, ++ktot, ++point) {
 +			float x[3], v[3];
 +			copy_v3_v3(x, point->co);
 +			copy_v3_v3(v, point->vel);
 +			mul_m4_v3(obmat, x);
 +			mul_mat3_m4_v3(obmat, v);
 +			
 +			BPH_mass_spring_set_rest_transform(data->id, ktot, curve->root_frame); /* hair orientation matrix (root frame) */
 +			BPH_mass_spring_set_motion_state(data->id, ktot, x, v);
 +		}
 +	}
 +}
 +
 +static void hair_calc_spring_force(HairSolverData *data, Object *ob, HairSystem *hsys, float time, SimDebugData *debug_data)
 +{
 +	HairParams *params = &hsys->params;
 +	const bool no_compress = true;
 +	
 +	float obmat[4][4];
 +	copy_m4_m4(obmat, ob->obmat);
 +	
 +	int kstart = 0;
 +	HairCurve *curve = hsys->curves;
 +	for (int i = 0; i < hsys->totcurves; ++i, ++curve) {
 +		HairPoint *point;
 +
 +#ifdef CLOTH_FORCE_SPRING_STRUCTURAL
 +		point = curve->points;
 +		for (int k = 0; k < curve->totpoints - 1; ++k, ++point) {
 +			BPH_mass_spring_force_spring_linear(data->id, kstart + k, kstart + k + 1, point->rest_length,
 +			                                    params->stretch_stiffness, params->stretch_damping, no_compress, 0.0f,
 +			                                    NULL, NULL, NULL);
 +		}
 +#endif
 +
 +#if 0
 +#ifdef CLOTH_FORCE_SPRING_GOAL
 +		float goal_x[3], goal_v[3];
 +		float k, scaling;
 +		
 +		s->flags |= CLOTH_SPRING_FLAG_NEEDED;
 +		
 +		// current_position = xold + t * (newposition - xold)
 +		interp_v3_v3v3(goal_x, verts[s->ij].xold, verts[s->ij].xconst, time);
 +		sub_v3_v3v3(goal_v, verts[s->ij].xconst, verts[s->ij].xold); // distance covered over dt==1
 +		
 +		scaling = parms->goalspring + s->stiffness * fabsf(parms->max_struct - parms->goalspring);
 +		k = verts[s->ij].goal * scaling / (parms->avg_spring_len + FLT_EPSILON);
 +		
 +		BPH_mass_spring_force_spring_goal(data, s->ij, s->matrix_ij_kl, goal_x, goal_v, k, parms->goalfrict * 0.01f, s->f, s->dfdx, s->dfdv);
 +#endif
 +#endif
 +
 +#ifdef CLOTH_FORCE_SPRING_BEND
 +		if (curve->totpoints >= 2) {
 +			HairFrameIterator iter;
 +			float x[3], x_prev[3], dir[3], frame[3][3], rot[3][3], target[3];
 +			
 +			/* frame starts in current root position */
 +			copy_m3_m3(frame, curve->root_frame);
 +			mul_mat3_m4_v3(obmat, frame[0]);
 +			mul_mat3_m4_v3(obmat, frame[1]);
 +			mul_mat3_m4_v3(obmat, frame[2]);
 +			normalize_m3(frame); /* avoid scaling from obmat */
 +			
 +			/* special handling of root point bending:
 +			 * use the first point twice
 +			 */
 +			point = curve->points;
 +			mul_v3_m3v3(target, frame, point->rest_target); /* target expressed in the current frame */
 +			BPH_mass_spring_force_spring_bending_angular(data->id, kstart, kstart, kstart + 1, target,
 +			                                             params->bend_stiffness, params->bend_damping);
 +			
 +			/* initialize x as the first point */
 +			BPH_mass_spring_get_motion_state(data->id, kstart, x, NULL);
 +			BPH_mass_spring_get_motion_state(data->id, kstart + 1, dir, NULL);
 +			sub_v3_v3(dir, x);
 +			normalize_v3(dir);
 +			
 +			/* align frame to first segment */
 +			rotation_between_vecs_to_mat3(rot, frame[2], dir);
 +			mul_m3_m3m3(frame, rot, frame);
 +			/* initialize frame iterator */
 +			BKE_hair_frame_init(&iter, dir);
 +			
 +			{ /* XXX DEBUG */
 +				BKE_sim_debug_data_add_m3(debug_data, x, frame, 0.8f*curve->avg_rest_length, 0.3f, 1.0f, "bending", hash_vertex(935, kstart));
 +				BKE_sim_debug_data_add_vector(debug_data, x, target, 0.7, 0.8, 0.0, "bending", hash_vertex(945, kstart));
 +			}
 +			
 +			++point;
 +			for (int k = 1; k < curve->totpoints - 1; ++k, ++point) {
 +				/* transport the frame to the next segment */
 +				copy_v3_v3(x_prev, x);
 +				BPH_mass_spring_get_motion_state(data->id, kstart + k, x, NULL);
 +				
 +				BKE_hair_frame_next_from_points(&iter, x_prev, x, rot);
 +				mul_m3_m3m3(frame, rot, frame);
 +				
 +				/* calculate bending target and build angular spring */
 +				mul_v3_m3v3(target, frame, point->rest_target); /* target expressed in the current frame */
 +				BPH_mass_spring_force_spring_bending_angular(data->id, kstart + k - 1, kstart + k, kstart + k + 1, target,
 +				                                             params->bend_stiffness, params->bend_damping);
 +				
 +				{ /* XXX DEBUG */
 +					BKE_sim_debug_data_add_m3(debug_data, x, frame, 0.8f*curve->avg_rest_length, 0.3f, 1.0f, "bending", hash_vertex(935, kstart + k));
 +					BKE_sim_debug_data_add_vector(debug_data, x, target, 0.7, 0.8, 0.0, "bending", hash_vertex(945, kstart + k));
 +		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list