From fdf89acc8634ecba4dfe66e20ff595c0c24ffdee Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Tue, 7 Jan 2020 16:46:56 +0100 Subject: Sculpt: Pose Brush with Inverse Kinematics This commits introduces the pose_ik_segments brush property in the Pose Brush. When increasing the IK segments count, the brush generates more segments and weights associations following the topology of the mesh. When moving the brush, these segments are transformed using an IK solver and they are used to deform the mesh. When pressing Ctrl, the brush controls the segments' roll rotation instead of using the IK solver. The brush falloff controls how much rotation is propagated from the first to the last segment in the chain. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D6389 --- source/blender/editors/sculpt_paint/paint_cursor.c | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'source/blender/editors/sculpt_paint/paint_cursor.c') diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 9021666c001..9bc587de6da 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -1461,15 +1461,30 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) cursor_draw_point_with_symmetry(pos, ar, gi.active_vertex_co, sd, vc.obact, rds); } - /* Draw pose brush origin */ + /* Draw pose brush origins. */ if (brush->sculpt_tool == SCULPT_TOOL_POSE) { immUniformColor4f(1.0f, 1.0f, 1.0f, 0.8f); if (update_previews) { BKE_sculpt_update_object_for_edit(depsgraph, vc.obact, true, false); - sculpt_pose_calc_pose_data( - sd, vc.obact, ss, gi.location, rds, brush->pose_offset, ss->pose_origin, NULL); + + /* Free the previous pose brush preview. */ + if (ss->pose_ik_chain_preview) { + sculpt_pose_ik_chain_free(ss->pose_ik_chain_preview); + } + + /* Generate a new pose brush preview from the current cursor location. */ + ss->pose_ik_chain_preview = sculpt_pose_ik_chain_init( + sd, vc.obact, ss, brush, gi.location, rds); + } + + /* Draw the pose brush rotation origins. */ + for (int i = 0; i < ss->pose_ik_chain_preview->tot_segments; i++) { + cursor_draw_point_screen_space(pos, + ar, + ss->pose_ik_chain_preview->segments[i].initial_orig, + vc.obact->obmat, + 3); } - cursor_draw_point_screen_space(pos, ar, ss->pose_origin, vc.obact->obmat, 5); } /* Draw 3D brush cursor */ @@ -1518,9 +1533,13 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) if (brush->sculpt_tool == SCULPT_TOOL_POSE) { immUniformColor4f(1.0f, 1.0f, 1.0f, 0.8f); GPU_line_width(2.0f); - immBegin(GPU_PRIM_LINES, 2); - immVertex3fv(pos, ss->pose_origin); - immVertex3fv(pos, gi.location); + + immBegin(GPU_PRIM_LINES, ss->pose_ik_chain_preview->tot_segments * 2); + for (int i = 0; i < ss->pose_ik_chain_preview->tot_segments; i++) { + immVertex3fv(pos, ss->pose_ik_chain_preview->segments[i].initial_orig); + immVertex3fv(pos, ss->pose_ik_chain_preview->segments[i].initial_head); + } + immEnd(); } -- cgit v1.2.3