Commit: 673c27adc915d916291c9865082e8c32e8ce898d
Author: Lukas Tönne
Date:   Sun Nov 16 15:22:54 2014 +0100
Branches: hair_system
https://developer.blender.org/rB673c27adc915d916291c9865082e8c32e8ce898d

Merge branch 'hair_immediate_fixes' into hair_system

Conflicts:
        source/blender/blenkernel/BKE_effect.h
        source/blender/blenkernel/intern/effect.c

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



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

diff --cc source/blender/blenkernel/BKE_effect.h
index b5665bb,c851454..395ac89
--- a/source/blender/blenkernel/BKE_effect.h
+++ b/source/blender/blenkernel/BKE_effect.h
@@@ -160,12 -189,32 +189,42 @@@ typedef struct SimDebugData 
  } 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_add_element(struct SimDebugData *debug_data, int 
type, const float v1[3], const float v2[3],
+                                     float r, float g, float b, const char 
*category, unsigned int hash);
+ void BKE_sim_debug_data_remove_element(struct SimDebugData *debug_data, 
unsigned int hash);
+ 
+ #define BKE_sim_debug_data_add_dot(debug_data, p, r, g, b, category, ...) { \
+       const float v2[3] = { 0.0f, 0.0f, 0.0f }; \
+       BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_DOT, p, v2, 
r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
+ }
+ 
+ #define BKE_sim_debug_data_add_circle(debug_data, p, radius, r, g, b, 
category, ...) { \
+       const float v2[3] = { radius, 0.0f, 0.0f }; \
+       BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_CIRCLE, p, 
v2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
+ }
+ 
+ #define BKE_sim_debug_data_add_line(debug_data, p1, p2, r, g, b, category, 
...) { \
+       BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_LINE, p1, p2, 
r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
+ }
+ 
+ #define BKE_sim_debug_data_add_vector(debug_data, p, d, r, g, b, category, 
...) { \
+       BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_VECTOR, p, d, 
r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
+ }
+ 
++#define BKE_sim_debug_data_add_m3(debug_data, p, m, scale, black, white, 
category, ...) { \
++      float v[3]; \
++      mul_v3_v3fl(v, m[0], scale); \
++      BKE_sim_debug_data_add_vector(debug_data, p, v, white, black, black, 
category, 1, __VA_ARGS__); \
++      mul_v3_v3fl(v, m[1], scale); \
++      BKE_sim_debug_data_add_vector(debug_data, p, v, black, white, black, 
category, 2, __VA_ARGS__); \
++      mul_v3_v3fl(v, m[2], scale); \
++      BKE_sim_debug_data_add_vector(debug_data, p, v, black, black, white, 
category, 3, __VA_ARGS__); \
++}
++
+ #define BKE_sim_debug_data_remove(debug_data, ...) \
+       BKE_sim_debug_data_remove_element(debug_data, 
SIM_DEBUG_HASH(__VA_ARGS__))
+ 
  void BKE_sim_debug_data_clear(struct SimDebugData *debug_data);
  void BKE_sim_debug_data_clear_category(struct SimDebugData *debug_data, const 
char *category);
  void BKE_sim_debug_data_free(struct SimDebugData *debug_data);
diff --cc source/blender/physics/intern/BPH_mass_spring.cpp
index 3e6712b,878f226..7e54d66
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@@ -1162,450 -1132,3 +1136,450 @@@ bool BPH_cloth_solver_get_texture_data(
        
        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, 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));
++                              BKE_sim_debug_data_add_m3(debug_data, x, frame, 
0.8f*curve->avg_rest_length, 0.3f, 1.0f, "bending", 935, kstart);
++                              BKE_sim_debug_data_add_vector(debug_data, x, 
target, 0.7, 0.8, 0.0, "bending", 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); 
/* targe

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to