Commit: 3a25fad7539767837a73db1a3f3f571889ad29e5
Author: Lukas Tönne
Date: Mon Dec 8 19:12:29 2014 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rB3a25fad7539767837a73db1a3f3f571889ad29e5
Use a simple low-pass filter to generate a smoother, more stable
direction vector for the hair stroke tool.
This is necessary for directional tools such as combing, where the
stroke direction can lead to unwanted results if it changes too
abruptly.
===================================================================
M source/blender/editors/hair/hair_edit.c
===================================================================
diff --git a/source/blender/editors/hair/hair_edit.c
b/source/blender/editors/hair/hair_edit.c
index e1e335a..71ff41f 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -270,6 +270,8 @@ typedef struct HairStroke {
bool first;
float lastmouse[2];
float zfac;
+
+ float smoothdir[2];
} HairStroke;
static int hair_stroke_init(bContext *C, wmOperator *op)
@@ -307,6 +309,7 @@ static bool hair_stroke_apply(bContext *C, wmOperator *op,
PointerRNA *itemptr)
BMEditStrands *edit = stroke->edit;
HairEditSettings *settings = &scene->toolsettings->hair_edit;
ARegion *ar = CTX_wm_region(C);
+ const float smoothfac = 0.9f; /* XXX should this be configurable? */
float mouse[2], mdelta[2], zvec[3], delta_max;
int totsteps, step;
@@ -317,6 +320,7 @@ static bool hair_stroke_apply(bContext *C, wmOperator *op,
PointerRNA *itemptr)
if (stroke->first) {
copy_v2_v2(stroke->lastmouse, mouse);
+ zero_v2(stroke->smoothdir);
stroke->first = false;
}
@@ -329,6 +333,9 @@ static bool hair_stroke_apply(bContext *C, wmOperator *op,
PointerRNA *itemptr)
totsteps = delta_max / (0.2f * BKE_brush_size_get(scene,
settings->brush)) + 1;
mul_v2_fl(mdelta, 1.0f / (float)totsteps);
+ /* low-pass filter to smooth out jittery pixel increments in the
direction */
+ interp_v2_v2v2(stroke->smoothdir, mdelta, stroke->smoothdir, smoothfac);
+
hair_init_viewdata(C, &tool_data.viewdata);
tool_data.scene = scene;
tool_data.ob = ob;
@@ -341,7 +348,7 @@ static bool hair_stroke_apply(bContext *C, wmOperator *op,
PointerRNA *itemptr)
zvec[0] = 0.0f; zvec[1] = 0.0f; zvec[2] = stroke->zfac;
ED_view3d_win_to_3d(ar, zvec, mouse, tool_data.loc);
- ED_view3d_win_to_delta(ar, mdelta, tool_data.delta, stroke->zfac);
+ ED_view3d_win_to_delta(ar, stroke->smoothdir, tool_data.delta,
stroke->zfac);
/* tools work in object space */
mul_m4_v3(tool_data.imat, tool_data.loc);
mul_mat3_m4_v3(tool_data.imat, tool_data.delta);
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs