[Bf-blender-cvs] [26de7d9] hair_system: Merge branch 'hair_immediate_fixes' into hair_system

Lukas Tönne noreply at git.blender.org
Sat Nov 15 16:02:31 CET 2014


Commit: 26de7d917209e8cd28b940eafeed77e833999c43
Author: Lukas Tönne
Date:   Sat Nov 15 15:51:16 2014 +0100
Branches: hair_system
https://developer.blender.org/rB26de7d917209e8cd28b940eafeed77e833999c43

Merge branch 'hair_immediate_fixes' into hair_system

Conflicts:
	source/blender/physics/BPH_mass_spring.h
	source/blender/physics/intern/BPH_mass_spring.cpp

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



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

diff --cc source/blender/blenkernel/BKE_effect.h
index c57250a,6688cd3..b5665bb
--- a/source/blender/blenkernel/BKE_effect.h
+++ b/source/blender/blenkernel/BKE_effect.h
@@@ -160,9 -161,9 +161,10 @@@ typedef struct SimDebugData 
  
  struct SimDebugData *BKE_sim_debug_data_new(void);
  void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, const char *category, int hash);
+ void BKE_sim_debug_data_add_circle(struct SimDebugData *debug_data, const float p[3], const float radius, float r, float g, float b, const char *category, int hash);
  void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, const char *category, int hash);
  void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, const char *category, int hash);
 +void BKE_sim_debug_data_add_m3(struct SimDebugData *debug_data, const float p[3], float m[3][3], float scale, float black, float white, const char *category, int hash);
  void BKE_sim_debug_data_remove(struct SimDebugData *debug_data, int hash);
  void BKE_sim_debug_data_clear(struct SimDebugData *debug_data);
  void BKE_sim_debug_data_clear_category(struct SimDebugData *debug_data, const char *category);
diff --cc source/blender/editors/space_view3d/view3d_intern.h
index 4006780,468e2eb..3f343b9
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@@ -133,10 -132,10 +134,11 @@@ void draw_motion_path_instance(Scene *s
                                 struct bAnimVizSettings *avs, struct bMotionPath *mpath);
  void draw_motion_paths_cleanup(View3D *v3d);
  
 -
 +/* drawhair.c */
 +bool draw_hair_system(Scene *scene, View3D *v3d, ARegion *ar, Base *base, struct HairSystem *hsys);
  
  /* drawobject.c */
+ void draw_object_bg_wire_color_set(const float color[3]);
  void draw_object(Scene *scene, struct ARegion *ar, View3D *v3d, Base *base, const short dflag);
  bool draw_glsl_material(Scene *scene, struct Object *ob, View3D *v3d, const char dt);
  void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob, const char dt, int outline);
diff --cc source/blender/physics/BPH_mass_spring.h
index e5eea0f,f2bd34e..2041e0d
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@@ -33,15 -33,10 +33,17 @@@ extern "C" 
  #endif
  
  struct Implicit_Data;
 -struct Object;
  struct ClothModifierData;
 +struct DerivedMesh;
 +struct EffectorWeights;
 +struct HairSolverData;
 +struct HairSystem;
 +struct HairParams;
 +struct Object;
 +struct Scene;
 +struct SimDebugData;
+ struct ListBase;
+ struct VoxelData;
  
  typedef enum eMassSpringSolverStatus {
  	BPH_SOLVER_SUCCESS              = (1 << 0),
@@@ -59,18 -54,8 +61,20 @@@ void BPH_cloth_solver_free(struct Cloth
  int BPH_cloth_solve(struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors);
  void BPH_cloth_solver_set_positions(struct ClothModifierData *clmd);
  
+ bool BPH_cloth_solver_get_texture_data(struct Object *ob, struct ClothModifierData *clmd, struct VoxelData *vd);
+ 
 +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
  }
  #endif
diff --cc source/blender/physics/intern/BPH_mass_spring.cpp
index 6a68676,798dd45..3e6712b
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@@ -875,445 -1138,23 +1142,470 @@@ int BPH_cloth_solve(Object *ob, float f
  	return 1;
  }
  
+ bool BPH_cloth_solver_get_texture_data(Object *UNUSED(ob), ClothModifierData *clmd, VoxelData *vd)
+ {
+ 	Cloth *cloth = clmd->clothObject;
+ 	HairGrid *grid;
+ 	float gmin[3], gmax[3];
+ 	
+ 	if (!clmd->clothObject || !clmd->clothObject->implicit)
+ 		return false;
+ 	
+ 	hair_get_boundbox(clmd, gmin, gmax);
+ 	
+ 	grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_cell_size, gmin, gmax);
+ 	cloth_continuum_fill_grid(grid, cloth);
+ 	
+ 	BPH_hair_volume_get_texture_data(grid, vd);
+ 	
+ 	BPH_hair_volume_free_vertex_grid(grid);
+ 	
+ 	return true;
+ }
++
 +/* ======== 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

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list