Commit: 4cb095d8db4c9b38ed62c22f74757f6368249071 Author: Lukas Tönne Date: Fri Aug 8 15:02:46 2014 +0200 Branches: hair_system https://developer.blender.org/rB4cb095d8db4c9b38ed62c22f74757f6368249071
Actual hair point size support for collision and, eventually, rendering. =================================================================== M source/blender/editors/physics/hair_ops.c M source/blender/editors/space_view3d/drawhair.c M source/blender/hair/intern/HAIR_scene.cpp M source/blender/makesdna/DNA_hair_types.h =================================================================== diff --git a/source/blender/editors/physics/hair_ops.c b/source/blender/editors/physics/hair_ops.c index 4d07680..9bf00c6 100644 --- a/source/blender/editors/physics/hair_ops.c +++ b/source/blender/editors/physics/hair_ops.c @@ -184,6 +184,9 @@ static bool hair_copy_particle_emitter_location(Object *UNUSED(ob), ParticleSyst static void hair_copy_from_particles_psys(Object *ob, HairSystem *hsys, ParticleSystem *psys, struct DerivedMesh *dm) { + /* scale of segment lengths to get point radius */ + const float seglen_to_radius = 2.0f / 3.0f; + HairCurve *hairs; int tothairs; float mat[4][4]; @@ -205,6 +208,7 @@ static void hair_copy_from_particles_psys(Object *ob, HairSystem *hsys, Particle HairPoint *points; int totpoints; float loc[3], tan[3]; + float radius; if (pa_cache->steps == 0) continue; @@ -217,6 +221,7 @@ static void hair_copy_from_particles_psys(Object *ob, HairSystem *hsys, Particle tan[0] = 0.0f; tan[1] = 0.0f; tan[2] = 1.0f; madd_v3_v3v3fl(hair->rest_tan, tan, hair->rest_nor, -dot_v3v3(tan, hair->rest_nor)); + radius = 0.0f; for (k = 0; k < totpoints; ++k) { ParticleCacheKey *pa_key = pa_cache + k; HairPoint *point = points + k; @@ -225,6 +230,18 @@ static void hair_copy_from_particles_psys(Object *ob, HairSystem *hsys, Particle /* apply rest position */ copy_v3_v3(point->co, point->rest_co); zero_v3(point->vel); + + if (k == 0) { + if (k < totpoints-1) + radius = seglen_to_radius * len_v3v3(pa_key->co, (pa_key+1)->co); + point->radius = radius; + } + else { + float prev_radius = radius; + if (k < totpoints-1) + radius = seglen_to_radius * len_v3v3(pa_key->co, (pa_key+1)->co); + point->radius = 0.5f * (radius + prev_radius); + } } } } diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c index a6a8be9..4e046a5 100644 --- a/source/blender/editors/space_view3d/drawhair.c +++ b/source/blender/editors/space_view3d/drawhair.c @@ -105,6 +105,7 @@ bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Ba /* ---------------- debug drawing ---------------- */ //#define SHOW_POINTS +//#define SHOW_SIZE //#define SHOW_ROOTS //#define SHOW_FRAMES //#define SHOW_SMOOTHING @@ -143,6 +144,26 @@ static void draw_hair_debug_points(HairSystem *hsys, HAIR_SolverDebugPoint *dpoi #endif } +static void draw_hair_debug_size(HairSystem *hsys, float tmat[4][4]) +{ +#ifdef SHOW_SIZE + int i, k; + + glColor3f(1.0f, 0.4f, 0.4f); + + for (i = 0; i < hsys->totcurves; ++i) { + HairCurve *hair = hsys->curves + i; + for (k = 0; k < hair->totpoints; ++k) { + HairPoint *point = hair->points + k; + + drawcircball(GL_LINE_LOOP, point->co, point->radius, tmat); + } + } +#else + (void)hsys; +#endif +} + static void draw_hair_debug_roots(HairSystem *hsys, struct DerivedMesh *dm) { #ifdef SHOW_ROOTS @@ -342,7 +363,7 @@ static void draw_hair_debug_cylinders(HairSystem *hsys, int totpoints, int valid float upvec[] = {0.0f, 0.0f, 1.0f}; float sidevec[] = {1.0f, 0.0f, 0.0f}; - float diameter = 0.05f; + float radius_factor = 1.0f; /* number of cylinder subdivisions */ int subdiv = 8; @@ -449,7 +470,7 @@ static void draw_hair_debug_cylinders(HairSystem *hsys, int totpoints, int valid /* and repeat */ copy_v3_v3(vert_data[offset], tangent); - mul_v3_fl(vert_data[offset], diameter); + mul_v3_fl(vert_data[offset], point->radius * radius_factor); add_v3_v3(vert_data[offset++], point->co); copy_v3_v3(vert_data[offset++], tangent); @@ -469,7 +490,7 @@ static void draw_hair_debug_cylinders(HairSystem *hsys, int totpoints, int valid mul_qt_v3(rot_quat, v_nor); copy_v3_v3(vert_data[offset], v_nor); - mul_v3_fl(vert_data[offset], diameter); + mul_v3_fl(vert_data[offset], point->radius * radius_factor); add_v3_v3(vert_data[offset++], point->co); copy_v3_v3(vert_data[offset++], v_nor); } @@ -509,6 +530,10 @@ static void draw_hair_debug_cylinders(HairSystem *hsys, int totpoints, int valid glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +#else + (void)hsys; + (void)totpoints; + (void)valid_points; #endif } @@ -521,10 +546,14 @@ void draw_hair_debug_info(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar int i; int tot_points = 0; int valid_points = 0; - + float imat[4][4]; + + invert_m4_m4(imat, rv3d->viewmatob); + glLoadMatrixf(rv3d->viewmat); glMultMatrixf(ob->obmat); + draw_hair_debug_size(hsys, imat); draw_hair_debug_roots(hsys, ob->derivedFinal); for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) { diff --git a/source/blender/hair/intern/HAIR_scene.cpp b/source/blender/hair/intern/HAIR_scene.cpp index 0a1cccf..c837a16 100644 --- a/source/blender/hair/intern/HAIR_scene.cpp +++ b/source/blender/hair/intern/HAIR_scene.cpp @@ -99,7 +99,7 @@ SolverData *SceneConverter::build_solver_data(Scene *scene, Object *ob, DerivedM HairPoint *hair_pt = hair->points + k; point->rest_co = transform_point(mat, hair_pt->rest_co); - point->radius = 0.0f; + point->radius = hair_pt->radius; point->cur.co = transform_point(mat, hair_pt->co); point->cur.vel = transform_direction(mat, hair_pt->vel); @@ -196,6 +196,8 @@ void SceneConverter::sync_rigidbody_data(SolverData *data, const HairParams &par point->rb_ghost.ghost.setRestitution(params.restitution); point->rb_ghost.ghost.setFriction(params.friction); + + point->bt_shape.setUnscaledRadius(point->radius); } } diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h index d9dc77d..faeb3b0 100644 --- a/source/blender/makesdna/DNA_hair_types.h +++ b/source/blender/makesdna/DNA_hair_types.h @@ -39,7 +39,9 @@ typedef struct HairPoint { float rest_co[3]; /* rest location in object space */ float co[3]; /* location in object space */ float vel[3]; /* velocity */ - int pad[3]; + float radius; /* thickness of a hair wisp */ + + int pad[2]; } HairPoint; typedef struct HairCurve { _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs